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