#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7;
int n, p, arr[N];
long long sum, s, ans;
int main() {
  cin >> n >> p;
  for (int i = 0; i < n; ++i) {
    scanf("%d", arr + i);
    sum += arr[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    s += arr[i];
    ans = max(ans, s % p + (sum - s) % p);
  }
  s = 0;
  for (int i = n - 1; i > 0; --i) {
    s += arr[i];
    ans = max(ans, s % p + (sum - s) % p);
  }
  cout << ans;
  return 0;
}
