#include <bits/stdc++.h>
using namespace std;
long long int v[3000084];
int main() {
  long long int n, k, cnt = 0, temp, mn = INFINITY;
  cin >> n >> k;
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
    mn = min(mn, v[i]);
  }
  for (long long int i = 0; i < n; i++) {
    temp = v[i] - mn;
    if (temp % k != 0) {
      cout << -1 << endl;
      return 0;
    } else
      cnt += temp / k;
  }
  cout << cnt << endl;
  return 0;
}
