#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  vector<int> v(n);
  int64_t sum1 = 0, sum2 = 0, best = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    sum2 += v[i];
  }
  sum1 += v[0];
  sum2 -= v[0];
  best = sum1 % p + sum2 % p;
  for (int i = 1; i < n - 2; ++i) {
    sum1 += v[i];
    sum2 -= v[i];
    int64_t x = sum1 % p + sum2 % p;
    if (x > best) best = x;
  }
  cout << best << endl;
  return 0;
}
