#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, p;
  cin >> n >> p;
  vector<long long> a(n + 1), sum(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] %= p;
    sum[i] = (sum[i - 1] + a[i]) % p;
  }
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    long long x = sum[i];
    long long y = (sum[n] - sum[i] + p) % p;
    ans = max(ans, x + y);
  }
  cout << ans << '\n';
  return 0;
}
