#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  scanf("%d %d", &n, &p);
  int nums[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
    nums[i] %= p;
    sum += nums[i];
    sum %= p;
  }
  int max_part = 0;
  int left = 0;
  int right = sum;
  for (int i = 0; i < n; i++) {
    left += nums[i];
    left %= p;
    right -= nums[i];
    while (right < 0) {
      right += p;
    }
    int part = left + right;
    if (part > max_part) {
      max_part = part;
    }
  }
  cout << max_part;
}
