#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
int main() {
  int n, m;
  b[0] = 0;
  cin >> n >> m;
  int s = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] %= m;
    b[i] = a[i] + b[i - 1];
  }
  for (int i = 1; i < n; i++) {
    s = max(s, b[i] % m + (b[n] - b[i]) % m);
  }
  cout << s << endl;
  return 0;
}
