#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int n, p, i, ans, a[100010], ans1[100010], ans2[100010];
int main() {
  cin >> n >> p;
  for (i = 1; i <= n; i++) cin >> a[i], a[i] %= p;
  for (i = 1; i <= n; i++) ans1[i] = (a[i] + ans1[i - 1]) % p;
  for (i = n; i >= 1; i--) ans2[i] = (a[i] + ans2[i + 1]) % p;
  for (i = 1; i < n; i++) ans = max(ans, ans1[i] + ans2[i + 1]);
  cout << ans;
  return 0;
}
