#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, k, s = 0;
  cin >> n >> k;
  vector<long long> a(n);
  for (auto &i : a) {
    cin >> i;
  }
  sort(a.rbegin(), a.rend());
  if ((a[0] - a[a.size() - 1]) % k != 0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < a.size(); i++) {
    if ((a[i] - a[a.size() - 1]) % k != 0) {
      cout << -1;
      return 0;
    }
    s += a[i] / k - (a[a.size() - 1] / k);
  }
  cout << s;
}
