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