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