#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  for (int tc = 0; tc < t; tc++) {
    int n, p;
    cin >> n >> p;
    vector<int> arr(n);
    long long int sum = 0;
    for (int i1 = 0; i1 < n; i1++) {
      cin >> arr[i1];
      sum += arr[i1];
    }
    long long int leftsum = 0, mx = 0;
    for (int i = 0; i < n; i++) {
      leftsum += arr[i];
      sum -= arr[i];
      mx = max(mx, leftsum % p + sum % p);
    }
    cout << mx << "\n";
  }
  return 0;
}
