#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e+5 + 50;
int n, p;
int num[MAX];
long long pre[MAX];
int Solve() {
  pre[0] = num[0];
  for (int i = 1; i < n; i++) {
    pre[i] = pre[i - 1] + num[i];
  }
  int ans1 = 0, ans2 = 0;
  int max = 0;
  for (int i = 1; i < n - 1; i++) {
    ans1 = 0;
    ans2 = 0;
    ans1 = pre[i] % p;
    ans2 = (pre[n - 1] - pre[i]) % p;
    if (ans1 + ans2 > max) max = ans1 + ans2;
  }
  return max;
}
int main(int argc, char *argv[]) {
  while (cin >> n >> p) {
    int a;
    for (int i = 0; i < n; i++) {
      cin >> a;
      num[i] = a % p;
    }
    if (n == 2) {
      cout << num[0] % p + num[1] % p << endl;
      continue;
    }
    int res = Solve();
    cout << res << endl;
  }
  return 0;
}
