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