#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100009;
unsigned long long a[MaxN], b[MaxN], c[MaxN];
int main() {
  unsigned long long n, ans = 0, p, sum = 0, sum2 = 0;
  cin >> n >> p;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    sum += a[i];
    b[i] = sum % p;
  }
  for (int i = n - 1; i >= 0; i--) {
    sum2 += a[i];
    c[i] = sum2 % p;
  }
  for (int i = 0; i < n; i++) ans = max(ans, (b[i] + c[i + 1]));
  cout << ans << endl;
  return 0;
}
