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