#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL << 60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;
template <typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
auto printVector = []<typename T>(ostream& out, vector<T> v) {
  copy(v.begin(), v.end(), ostream_iterator<T>(out, " "));
};
int n, k, a[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  int rsum =
      accumulate(a, a + n, 0, [](int acc, int x) { return (acc + x) % k; });
  int lsum = 0;
  int res = 0;
  for (int i = 0; i + 1 < n; i++) {
    lsum += a[i];
    rsum -= a[i];
    lsum %= k, rsum %= k;
    if (rsum < 0) rsum += k;
    res = max(lsum + rsum, res);
  }
  cout << res << endl;
  return 0;
}
