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