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