#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using pll = pair<ll, ll>;
using vll = vector<pll>;
using MAP = map<ll, ll>;
using sl = set<ll>;
using sll = set<pll>;
using MAPs = map<ll, sl>;
using MAPv = map<ll, vl>;
const ll inf = LLONG_MAX;
const ll mod = 1e9 + 7;
const ll N = 1e5 + 5;
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
ll n, p, a[N], pre[N], suf[N];
ll add(ll a, ll b, ll m) { return (a % m + b % m) % m; }
ll sub(ll a, ll b, ll m) { return ((a - b) % m + m) % m; }
void MAIN() {
  cin >> n >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  ll 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_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t-- > 0) {
    MAIN();
  }
}
