#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long n, k, m = 2e+18, ans = 0;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m = min(m, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if ((a[i] - m) % k != 0) {
      cout << -1;
      return 0;
    } else {
      ans += (a[i] - m) / k;
    }
  }
  cout << ans;
  return 0;
}
