rt
#include <bits/stdc++.h>
#define int __int128
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') f *= (ch == '-' ? -1 : 1), ch = getchar();
while(ch >= 48 && ch <= 57) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return x * f;
}
void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 ^ 48);
}
int n, p, sum = 0, maxx = -0x3f3f3f3f, f[1000010], a[1000010], res[1000010];
signed main() {
n = read(), p = read();
for (int i = 1; i <= n; i++)
a[i] = read();
for (int i = 1; i <= n; i++) {
if(sum < 0) sum = 0;
sum += a[i];
maxx = max(maxx, sum);
f[i] = maxx;
}
res[1] = f[1];
maxx = res[1] + f[1];
int ans = res[1];
for (int i = 2; i <= n; i++) {
res[i] = maxx;
maxx = max(maxx, res[i] + f[i]);
ans = max(ans, res[i]);
}
write(ans >= 0 ? ans % p : -(abs(ans) % p));
return 0;
}