#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n = 0, k = 0, x = 0, step = 0, i = 0;
  vector<long long int> v;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  bool flag = 0;
  for (i = 1; i < n; i++) {
    long long int dif = v[i] - v[0];
    if (dif % k == 0) {
      step += dif / k;
    } else {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "-1" << endl;
  else
    cout << step << endl;
  return 0;
}
