#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long mn = a[0], mx = a[0], done = 0;
  for (long long i = 1; i < n; i++) {
    if (abs(a[i] - a[i - 1]) % k != 0) {
      cout << "-1" << endl;
      done = -1;
      break;
    } else {
      if (mx < a[i]) mx = a[i];
      if (mn > a[i]) mn = a[i];
    }
  }
  if (done != -1) {
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      ans += (a[i] - mn) / k;
    }
    cout << ans << endl;
  }
}
