#include <bits/stdc++.h>
using namespace std;
long long a[100001], s, p, mx = 0;
int main() {
  int n;
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    a[i] = a[i - 1] + s;
  }
  for (int i = 1; i < n; i++)
    if ((a[n] - a[i]) % p + a[i] % p > mx) mx = (a[n] - a[i]) % p + a[i] % p;
  cout << mx << '\n';
  return 0;
}
