#include <bits/stdc++.h>
using namespace std;
const long long ARRAY_SIZE = 100005;
long long n, p, a[ARRAY_SIZE];
long long add(long long x) { return (x % p + p) % p; }
signed main() {
  cin >> n >> p;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = add(a[i - 1] + a[i]);
  }
  long long ans = 0;
  for (long long i = 1; i < n; i++) ans = max(ans, a[i] + add(a[n] - a[i]));
  cout << ans;
}
