#include <bits/stdc++.h>
using namespace std;
long long sum, sum1, ans, rans;
int main() {
  int n, p, i, j, k, a[100010];
  cin >> n >> p;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (i = 0; i < n; i++) {
    sum1 += a[i];
    sum -= a[i];
    ans = (sum % p) + (sum1 % p);
    rans = max(ans, rans);
  }
  cout << rans;
  return 0;
}
