#include <bits/stdc++.h>
using namespace std;
int n, p;
int sum[200000];
int main() {
  scanf("%d %d", &n, &p);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &sum[i]);
    sum[i] = (sum[i - 1] + sum[i]) % p;
  }
  int ans = 0;
  int l, r;
  for (int i = 1; i < n; ++i) {
    l = sum[i];
    r = sum[n] - sum[i];
    if (r < 0) r += p;
    if (l + r > ans) ans = l + r;
  }
  printf("%d\n", ans);
  return 0;
}
