#include <bits/stdc++.h>
int main() {
  int n, p;
  long long max = 0;
  scanf("%d %d", &n, &p);
  long long *A = (long long *)calloc(n, sizeof(long long));
  long long *diem = (long long *)calloc(n, sizeof(long long));
  scanf("%I64d", &A[0]);
  diem[0] = A[0];
  for (int i = 1; i < n; i++) {
    scanf("%I64d", &A[i]);
    diem[i] = diem[i - 1] + A[i];
  }
  for (int i = 0; i < n; i++) {
    long long rem = diem[i] % p + (diem[n - 1] - diem[i]) % p;
    if (rem > max) {
      max = rem;
    }
  }
  printf("%I64d", max);
  free(A);
  free(diem);
  return 0;
}
