#include <bits/stdc++.h>
using namespace std;
int n, a[100005], k;
int main() {
  cin >> n >> k;
  int m = 1e9;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m = min(a[i], m);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int q = a[i] - m;
    if (q % k != 0) {
      cout << "-1\n";
      return 0;
    }
    ans += q / k;
  }
  cout << ans << '\n';
  return 0;
}
