#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  long long arr[n + 2];
  arr[0] = 0;
  arr[n + 1] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    arr[i] += arr[i - 1];
  }
  long long mx = 0;
  for (int i = 1; i < n; i++)
    mx = max(mx, (arr[i] % p) + (arr[n] - arr[i]) % p);
  cout << mx << endl;
}
