#include <bits/stdc++.h>
using namespace std;
int main() {
  long long arr[100005] = {0}, x;
  long n, p;
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    arr[i] = arr[i - 1] + x;
  }
  long long mx = 0;
  for (int i = 1; i <= n; i++) {
    long long x = arr[i] % p;
    long long y = (arr[n] - arr[i]) % p;
    mx = max(mx, x + y);
  }
  printf("%lld\n", mx);
}
