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