#include <bits/stdc++.h>
using namespace std;
const long long MOD9 = 1e9 + 7;
const long long MAX = 1e5 + 10;
const double eps = 0.99;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> vec;
  int mi = INT_MAX;
  for (long long i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec.push_back(x);
    mi = min(mi, x);
  }
  long long res = 0;
  for (long long i = 0; i < vec.size(); i++) {
    if ((vec[i] - mi) % m != 0) {
      cout << -1 << endl;
      return 0;
    }
    res += (vec[i] - mi) / m;
  }
  cout << res << endl;
}
