#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const long double pi = acos(-1);
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, p, sum = 0;
  cin >> n >> p;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  long long s = 0, m = 0;
  for (long long i = 0; i < n; i++) {
    s += v[i];
    sum -= v[i];
    long long a = sum % p, b = s % p;
    if (a + b > m) {
      m = a + b;
    }
  }
  cout << m << endl;
  return 0;
}
