#include <bits/stdc++.h>
using namespace std;
long long l[100010], r[100010], a[100010];
int main() {
  int n, p;
  while (cin >> n >> p) {
    memset(l, 0, sizeof(l));
    memset(r, 0, sizeof(r));
    cin >> a[0];
    l[0] = a[0];
    for (int i = 1; i < n; i++) {
      cin >> a[i];
      l[i] = l[i - 1] + a[i];
    }
    int t = n - 1;
    r[0] = a[t];
    for (int i = 1; i < n; i++) {
      r[i] = r[i - 1] + a[t - i];
    }
    long long ans = 0;
    for (int i = 0; i < n - 1; i++) {
      if ((l[i] % p) + (r[t - 1 - i] % p) > ans)
        ans = (l[i] % p) + (r[t - 1 - i] % p);
    }
    cout << ans << endl;
  }
  return 0;
}
