#include <bits/stdc++.h>
using namespace std;
long long int a[100007], n, p, s[100007], ans = 0;
inline long long int read() {
  long long int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
inline void writ(long long int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) writ(x / 10);
  putchar(x % 10 + '0');
}
inline void write(long long int x) {
  writ(x);
  putchar('\n');
}
int main() {
  n = read();
  p = read();
  for (int i = 1; i <= n; ++i) a[i] = read(), s[i] = s[i - 1] + a[i];
  for (int i = 1; i < n; ++i) ans = max(ans, s[i] % p + (s[n] - s[i]) % p);
  write(ans);
  return 0;
}
