#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, p;
long long a[N], pref[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> p;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = pref[i - 1] + a[i];
  }
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    long long left = pref[i];
    long long right = pref[n] - left;
    ans = max(ans, (left % p) + (right % p));
  }
  cout << ans;
  return 0;
}
