#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int L, R = 0;
int ans;
int p;
int a[N];
int main() {
  cin >> n >> p;
  for (int i = 0; i < n; ++i) cin >> a[i];
  L = a[0] % p;
  for (int i = 1; i < n; ++i) R += a[i] % p;
  ans = L % p + R % p;
  for (int i = 1; i < n; ++i) {
    L += a[i] % p;
    R -= a[i] % p;
    ans = max(ans, L % p + R % p);
  }
  cout << ans;
  return 0;
}
