#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n, p;
  cin >> n >> p;
  long long int numbers[n];
  for (long long int i = 0; i < n; i++) cin >> numbers[i];
  long long int sum[n];
  sum[0] = numbers[0];
  for (long long int i = 1; i < n; i++) sum[i] = sum[i - 1] + numbers[i];
  vector<long long int> answer;
  for (int i = 0; i < n - 1; i++) {
    answer.push_back(sum[i] % p + (sum[n - 1] - sum[i]) % p);
  }
  sort(answer.begin(), answer.end());
  cout << answer[n - 2];
  return 0;
}
