#include <bits/stdc++.h>
using namespace std;
int main() {
  long long sum = 0, n, k, mini = 10000000001;
  cin >> n >> k;
  long long t[n];
  int ok = 1;
  for (long long i = 0; i < n; i++) {
    cin >> t[i];
    mini = min(mini, t[i]);
  }
  for (long long i = 0; i < n; i++) {
    if (t[i] == mini) continue;
    if ((t[i] - mini) % k != 0) {
      ok = 0;
      break;
    }
    sum += (t[i] - mini) / k;
  }
  if (!ok)
    cout << "-1" << endl;
  else
    cout << sum << endl;
}
