#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, a[100000];
  scanf("%d %d", &n, &p);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  long long score1, score2, X, S = 0;
  score1 = score2 = 0;
  score1 += a[0];
  for (int i = 1; i < n; i++) score2 += a[i];
  X = score1 % p + score2 % p;
  S = max(S, X);
  int bar = 0;
  while (++bar < n) {
    score1 += a[bar];
    score2 -= a[bar];
    X = score1 % p + score2 % p;
    S = max(S, X);
  }
  printf("%d\n", S);
  return 0;
}
