#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, p;
  cin >> n >> p;
  vector<int> dat(n + 1);
  vector<long long> pre(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> dat[i];
  }
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + dat[i];
  }
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans = max(ans, pre[i] % p + (pre[n] - pre[i]) % p);
  }
  cout << ans << endl;
  return 0;
}
