#include <bits/stdc++.h>
using namespace std;
long long int C[100005];
int main() {
  int n, p;
  scanf("%d %d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%I64d", &C[i]);
  for (int i = 1; i <= n; i++) C[i] += C[i - 1];
  long long int Max = 0;
  for (int i = 1; i < n; i++) Max = max(Max, C[i] % p + (C[n] - C[i]) % p);
  cout << Max << endl;
}
