#include <bits/stdc++.h>
using namespace std;
int const N = 100000;
long long a[N + 5], res;
int n, p;
int main() {
  cin >> n >> p;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i < n; ++i) res = max(res, a[i] % p + (a[n] - a[i]) % p);
  cout << res;
  return 0;
}
