#include <bits/stdc++.h>
using namespace std;
long long int ara[100005];
int main() {
  long long int n, p, i, j, sum = 0;
  scanf("%I64d %I64d", &n, &p);
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &ara[i]);
    sum += ara[i];
  }
  long long int ans = 0, first_half = 0, last_half = 0, temp = 0;
  for (i = 1; i < n; i++) {
    first_half = (first_half + ara[i]) % p;
    temp += ara[i];
    last_half = (sum - temp) % p;
    ans = max(ans, first_half + last_half);
  }
  printf("%I64d\n", ans);
  return 0;
}
