#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, p, a[100000], sum = 0;
  cin >> n >> p;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= p;
  }
  sum = (sum + p - (a[0] % p)) % p;
  int cur = a[0] % p, ans = cur + sum;
  for (int i = 1; i < n - 1; ++i) {
    cur = (cur + a[i]) % p, sum = (sum + p - (a[i] % p)) % p;
    ans = max(ans, cur + sum);
  }
  cout << ans;
  return 0;
}
