#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n, p;
  long long sum = 0;
  cin >> n >> p;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long s = 0, sum2 = 0, sum3;
  for (int i = 0; i < n; i++) {
    sum2 += a[i];
    sum3 = sum - sum2;
    int t = (sum2 % p) + (sum3 % p);
    if (t > s) s = t;
  }
  cout << s << endl;
  return 0;
}
