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