#include <bits/stdc++.h>
unsigned long long mulmod(unsigned long long a, unsigned long long b,
                          unsigned long long c) {
  unsigned long long x = 0, y = a % c;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x + y) % c;
    }
    y = (y * 2) % c;
    b /= 2;
  }
  return x % c;
}
unsigned long long pow(unsigned long long a, unsigned long long b,
                       unsigned long long c) {
  unsigned long long x = 1, y = a;
  while (b > 0) {
    if (b & 1) x = mulmod(x, y, c);
    y = mulmod(y, y, c);
    b >>= 1;
  }
  return x;
}
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> second(n);
  for (int i = 0; i < n; i++) {
    cin >> second[i];
  }
  bool flg = 0;
  long long ans = *min_element(second.begin(), second.end());
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    if ((second[i] - ans) % k != 0) {
      flg = 1;
      break;
    } else {
      cnt += (second[i] - ans) / k;
    }
  }
  if (!flg) {
    cout << cnt << endl;
  } else {
    cout << "-1\n";
  }
  return 0;
}
