#include <bits/stdc++.h>
using namespace std;
long long a, b[555555], c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
    v, w, x, y, z, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, mm, nn, oo,
    pp, qq, rr, ss, tt, uu, vv, ww, xx, yy, zz;
int main() {
  cin >> a;
  cin >> o;
  for (c = 0; c < a; c++) {
    cin >> b[c];
  }
  for (d = 0; d < a - 1; d++) {
    if (b[d] % o == b[d + 1] % o) r++;
  }
  if (r < a - 1)
    cout << -1;
  else {
    sort(b, b + a);
    for (f = 0; f < a; f++) {
      h += b[f];
      i += b[0];
    }
    j = h - i;
    j = j / o;
    cout << j;
  }
}
