#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j, k, l, m, b, t, sum, sum1, flag, max1, min1;
  cin >> n >> m;
  long long a[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sum = 0;
  long long pre[100009];
  pre[1] = a[1];
  for (i = 2; i <= n; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  max1 = INT_MIN;
  for (i = 1; i <= n; i++) {
    k = pre[i];
    l = pre[n] - pre[i];
    k = k % m;
    l = l % m;
    max1 = max(k + l, max1);
  }
  cout << max1 << endl;
}
