#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, a;
  cin >> n >> k;
  std::vector<int> v;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  long long ans = 0, b = 0;
  for (int i = 1; i < n; i++) {
    if ((v[i] - v[0]) % k == 0) {
      ans = ans + (v[i] - v[0]) / k;
    } else {
      b = b + 1;
    }
  }
  if (b == 0) {
    cout << ans;
  } else {
    cout << "-1";
  }
  return 0;
}
