#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long N = 1e6 + 5;
const long long mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
long long test = 1, n, p, a[N], pre[N], suf[N];
vector<long long> adj[N];
void solve() {
  cin >> n >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long sum = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    sum = (sum + a[i]) % p;
    pre[i] = sum;
  }
  sum = 0;
  for (int i = n; i >= 1; i--) {
    sum = (sum + a[i]) % p;
    suf[i] = sum;
  }
  for (int i = 1; i < n; i++) ans = max(ans, pre[i] + suf[i + 1]);
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(15);
  ;
  for (int i = 1; i <= test; i++) {
    solve();
  }
}
