#include <bits/stdc++.h>
using namespace std;
long long pre[200005];
int main() {
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    pre[i] = pre[i - 1] + x;
  }
  long long maz = -1;
  for (long long i = 1; i <= n - 1; i++) {
    long long tmp = pre[i];
    long long tmp2 = pre[n] - tmp;
    long long ans = (tmp % p) + (tmp2 % p);
    maz = max(maz, ans);
  }
  cout << maz;
}
