#include <bits/stdc++.h>
using namespace std;
long long int a[100005];
int main() {
  int n, p;
  while (cin >> n >> p) {
    int x;
    cin >> x;
    a[0] = x;
    for (int i = 1; i < n; i++) {
      cin >> x;
      a[i] = a[i - 1] + x;
    }
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
      if (a[i] % p + (a[n - 1] - a[i]) % p > sum) {
        sum = a[i] % p + (a[n - 1] - a[i]) % p;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
