#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, p;
  cin >> n >> p;
  long long sum1 = 0, sum2 = 0, ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum2 += a[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    sum1 += a[i];
    sum2 -= a[i];
    ans = max(sum1 % p + sum2 % p, ans);
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
}
