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