#include <bits/stdc++.h>
using namespace std;
void merge(long int a[], long int s1, long int e1, long int s2, long int e2) {
  long int n = (e1 - s1) + (e2 - s2) + 2;
  long int b[n];
  long int k = 0, i = s1, j = s2;
  while (i <= e1 && j <= e2) {
    if (a[i] < a[j]) {
      b[k] = a[i];
      k++;
      i++;
    } else {
      b[k] = a[j];
      k++;
      j++;
    }
  }
  while (i <= e1) {
    b[k] = a[i];
    k++;
    i++;
  }
  while (j <= e2) {
    b[k] = a[j];
    k++;
    j++;
  }
  k = 0;
  i = s1;
  while (i <= e2) {
    a[i] = b[k];
    k++;
    i++;
  }
}
void mergesort(long int a[], long int s, long int e) {
  long int mid = (s + e) / 2;
  if (s == e) return;
  mergesort(a, s, mid);
  mergesort(a, mid + 1, e);
  merge(a, s, mid, mid + 1, e);
}
long int dam(string s) {
  long int d = 0, t = 1;
  for (long int i = 0; i < s.size(); i++) {
    if (s[i] == 'S')
      d += t;
    else
      t = t * 2;
  }
  return d;
}
int main() {
  long int n, p;
  cin >> n >> p;
  long int a[n];
  long long int s1 = 0, s2 = 0, t1 = 0, t2 = 0;
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
    s1 += a[i];
  }
  for (long int i = 0; i < n; i++) {
    t1 = (s1 - a[i]) % p + (s2 + a[i]) % p;
    if (t1 >= t2) t2 = t1;
    s1 -= a[i];
    s2 += a[i];
  }
  cout << t2;
}
