#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
void solve() {
  long long int n, p;
  cin >> n >> p;
  std::vector<long long int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  std::vector<long long int> forward(n + 1);
  long long int tot = 0;
  for (int i = 0; i < n; ++i) {
    tot += v[i];
    forward[i + 1] = tot;
  }
  long long int cursum;
  long long int minans = LLONG_MIN;
  for (int i = 1; i < n; ++i) {
    cursum = forward[i];
    minans = max(minans, cursum % p + (tot - cursum) % p);
  }
  cout << minans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
