#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long n, k;
  cin >> n >> k;
  vector<long> v;
  long i, x;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  long long count = 0;
  sort(v.begin(), v.end(), greater<long>());
  for (i = 0; i < n; i++) {
    if ((v[i] - v[n - 1]) % k == 0) {
      count = count + ((v[i] - v[n - 1]) / k);
    } else {
      cout << "-1";
      return 0;
    }
  }
  cout << count;
  return 0;
}
