#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int pre[maxn], suf[maxn], a[maxn], now, n, MOD, ans;
set<int> s;
int main() {
  scanf("%d%d", &n, &MOD);
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  for (int i = (1); i <= (n); i++) {
    now = (now + a[i]) % MOD;
    pre[i] = now;
  }
  now = 0;
  for (int i = n; i >= 1; i--) {
    now = (now + a[i]) % MOD;
    suf[i] = now;
  }
  for (int i = (1); i <= (n - 1); i++) ans = max(ans, pre[i] + suf[i + 1]);
  printf("%d\n", ans);
  return 0;
}
