#include <bits/stdc++.h>
#pragma gcc optimize("Ofast,no-stack-protector,tune=native")
#pragma gcc optimize("sse,sse2,sse3,sse4,ssse3")
#pragma gcc optimize("abm,mmx,avx,avx2,unroll-loops,fast-math,section-anchors")
using namespace std;
int main() {
  long long n, p, sm = 0, rr = 0, ans = 0;
  cin >> n >> p;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sm += a[i];
  }
  for (int i = n - 1; i >= 1; i--) {
    ans = max(ans, (sm - a[i]) % p + (rr + a[i]) % p);
    sm -= a[i];
    rr += a[i];
  }
  cout << ans;
}
