#include <bits/stdc++.h>
using namespace std;
long long a[100005], sum[100005];
int main() {
  int n, m;
  long long maxx = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sum[1] = a[1];
  for (int i = 2; i <= n; i++) {
    sum[i] += sum[i - 1] + a[i];
  }
  for (int i = 1; i <= n / 2; i++) {
    maxx = max(sum[i] % m + (sum[n] - sum[i]) % m, maxx);
  }
  printf("%lld\n", maxx);
  return 0;
}
