#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); }
long long mpow(long long base, long long exp) {
  base %= 1000000007;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % 1000000007;
    base = (base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}
void solve() {}
long long flip(bool a, bool b, bool c, long long val) { return 0; }
int32_t main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, k;
  cin >> n >> k;
  vector<long long> z;
  for (long long i = 0; i < n; i++) {
    long long val;
    cin >> val;
    z.push_back(val);
  }
  sort((z).begin(), (z).end());
  long long m1 = z[0];
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    long long d = z[i] - m1;
    if (d % k == 0) {
      long long r = d / k;
      ans += r;
    } else {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
