#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int n, k, t;
  cin >> n >> k;
  while (n--) {
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  int mod = v[0] % k;
  long long ans = 0;
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] % k != mod) {
      cout << "-1\n";
      return 0;
    }
    ans += (long long)((v[i] - v[0]) / k);
  }
  cout << ans << '\n';
}
