#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long m;
  cin >> m;
  long long sum = 0LL;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long solve = 0LL;
  long long S = 0LL;
  for (int i = 1; i < n; i++) {
    S += a[i];
    long long SS = sum - S;
    long long s1 = S % m;
    long long s2 = SS % m;
    solve = max(solve, s1 + s2);
  }
  cout << solve << '\n';
  return 0;
}
