#include <bits/stdc++.h>
using namespace std;
const long long homura = 1e5 + 2, rachel = 1e9 + 7;
void solve() {
  long long n, i, j, k, l, m;
  cin >> n >> m;
  long long a[n + 1], prf[n + 2];
  prf[0] = 0;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    prf[i] = prf[i - 1] + a[i];
  }
  long long ans = INT_MIN;
  for (i = 1; i < n; ++i) {
    long long tmp = (prf[i] % m) + ((prf[n] - prf[i]) % m);
    ans = max(ans, tmp);
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
