#include <bits/stdc++.h>
using namespace std;
inline void out(int a) { printf("%d\n", a); }
inline void out(int a, int b) { printf("%d %d\n", a, b); }
inline void outf(double a) { printf("%3.lf\n", a); }
inline void outf(double a, double b) { printf("%3.lf %3.lf\n", a, b); }
inline void base() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
int main() {
  base();
  long long n, k;
  cin >> n >> k;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> data;
  for (int(i) = 0; (i) < (n); (i)++) {
    long long a;
    cin >> a;
    data.push_back(a);
  }
  long long ans = 0;
  sort(data.begin(), data.end());
  for (int(i) = (1); (i) <= (n - 1); (i)++) {
    if ((data[i] - data[0]) % k != 0) {
      cout << -1 << endl;
      return 0;
    } else {
      ans += (data[i] - data[0]) / k;
    }
  }
  cout << ans << endl;
  return 0;
}
