#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long n, m;
long long a[maxn], sum1[maxn], sum2[maxn];
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum1[i] = sum1[i - 1] + a[i];
  }
  for (int i = n; i >= 1; i--) {
    sum2[i] = sum2[i + 1] + a[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    ans = max(ans, (sum1[i] % m) + (sum2[i + 1] % m));
  }
  cout << ans << endl;
  return 0;
}
