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