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