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