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