#include <bits/stdc++.h>
using namespace std;
long long n, m, sm, ans, sum;
int main() {
  cin >> n >> m;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i], sm += v[i];
  for (int i = 0; i < n; i++) {
    sum += v[i], sm -= v[i];
    ans = max(ans, (sum % m) + (sm % m));
  }
  cout << ans << endl;
}
