#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, p;
  cin >> n >> p;
  vector<long long> nums(n);
  vector<long long> pfx(n + 1);
  pfx[0] = 0;
  for (long long i = 0; i < n; i++) {
    cin >> nums[i];
    pfx[i + 1] = pfx[i] + nums[i];
  }
  pfx[n] = pfx[n - 1] + nums[n - 1];
  long long ans = INT_MIN;
  for (long long i = 1; i <= n; i++) {
    long long h1 = pfx[i] % p;
    long long h2 = (pfx[n] - pfx[i]) % p;
    ans = max(ans, h1 + h2);
  }
  cout << ans;
  return 0;
}
