#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100, INF = 0x3f3f3f3f;
long long sum[MAXN];
int main() {
  int n, p, x;
  cin >> n >> p;
  sum[0] = 0;
  for (int i = 1; i <= n; ++i) cin >> x, sum[i] = sum[i - 1] + x % p;
  long long r = -INF;
  for (int i = 1; i < n; ++i) r = max(r, (sum[i] % p) + (sum[n] - sum[i]) % p);
  cout << r << endl;
}
