#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  long long int d = 0;
  long long int c, z[a];
  long long int s1, s2, daux;
  for (int i = 0; i < a; i++) {
    cin >> c;
    if (i == 0)
      z[0] = c;
    else
      z[i] = c + z[i - 1];
  }
  for (int i = 0; i < (a - 1); i++) {
    s1 = z[i];
    s2 = z[a - 1] - s1;
    daux = s2 % b + s1 % b;
    if (daux > d) d = daux;
  }
  cout << d << endl;
  return 0;
}
