#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans, L, R = 0;
  L = a[0];
  for (int j = 1; j < n; j++) R += a[j] % p;
  ans = L % p + R % p;
  int maxnum = ans;
  for (int i = 1; i < n; i++) {
    L += a[i] % p;
    R -= a[i] % p;
    if (L % p + R % p > maxnum) maxnum = L % p + R % p;
  }
  cout << maxnum;
  return 0;
}
