#include <bits/stdc++.h>
using namespace std;
const long long mx = (1e5) + 1;
const long long mod = 1000000007;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, p;
  cin >> n >> p;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> pre(n);
  pre[0] = a[0];
  for (int i = 1; i < n; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  long long ans = 0;
  long long i = 0;
  while (i < n) {
    long long value = pre[i] % p;
    long long value1 = (pre[n - 1] - pre[i]) % p;
    long long x = value + value1;
    ans = max(ans, x);
    i++;
  }
  cout << ans << "\n";
  return 0;
}
