#include <bits/stdc++.h>
using namespace std;
long long sum[100500];
int main() {
  long long n, p;
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    sum[i] = sum[i - 1] + x;
  }
  long long mx = -1;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, sum[i] % p + (sum[n] - sum[i]) % p);
  }
  cout << mx << endl;
  return 0;
}
