#include <bits/stdc++.h>
using namespace std;
void code() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if ((a[i] - a[0]) % k != 0) {
      cout << "-1" << endl;
      return;
    }
    ans += ((a[i] - a[0]) / k);
  }
  cout << ans << endl;
}
signed main() { code(); }
