#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n, p;
  cin >> n >> p;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int w;
    cin >> w;
    a[i] = (w + sum) % p;
    sum = (sum + w) % p;
  }
  int max = -1;
  for (int i = 0; i < n; i++) {
    int l, r;
    if (sum - a[i] >= 0) {
      r = sum - a[i];
    } else {
      r = sum - a[i] + p;
    }
    if (a[i] + r > max) max = a[i] + r;
  }
  cout << max << endl;
  return 0;
}
