#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e5 + 10;
int a[N];
int main() {
  int n, p;
  cin >> n >> p;
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    tot += a[i];
  }
  long long ans = 0;
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sum += a[i];
    ans = max(ans, sum % p + (tot - sum) % p);
  }
  cout << ans << endl;
  return 0;
}
