#include <bits/stdc++.h>
const long long INF = 1e16;
using namespace std;
inline void solve() {
  int n, p;
  cin >> n >> p;
  long long int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i > 0) a[i] += a[i - 1];
  }
  long long int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, a[i] % p + (a[n - 1] - a[i]) % p);
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
