#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 1;
long long n, p, a[N];
long long cs[N];
int main() {
  scanf("%lld %lld", &n, &p);
  for (int i = 0; i < n; ++i) scanf("%lld", a + i);
  for (int i = 1; i <= n; ++i) cs[i] += cs[i - 1] + a[i - 1];
  long long res = 0;
  for (int i = 1; i < n; ++i) {
    res = max(res, (cs[i] % p) + ((cs[n] - cs[i]) % p));
  }
  printf("%lld\n", res);
  return 0;
}
