#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const long long MOD = 1e9 + 7;
long long n_bits(long long n) {
  long long x = __builtin_popcount(n);
  return x;
}
int pow(int a, int b, int m) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    int n, p;
    cin >> n >> p;
    long long sum = 0;
    int a[n];
    long long left = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    long long final = (sum - a[n - 1]) % p + a[n - 1] % p;
    sum -= a[n - 1];
    left = a[n - 1];
    for (int i = n - 2; i > 0; i--) {
      left += a[i];
      sum -= a[i];
      final = max(final, left % p + sum % p);
    }
    cout << final;
  }
  return 0;
}
