#include <bits/stdc++.h>
using namespace std;
long long int small(long long int ara[], int n) {
  long long int temp = 999999999000;
  for (int i = 0; i < n; i++) {
    if (ara[i] <= temp) temp = ara[i];
  }
  return temp;
}
int main() {
  long long int n, k, ans = 0, temp = 1;
  cin >> n >> k;
  long long int a[n], s[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int lo = small(a, n);
  for (long long int i = 0; i < n; i++) {
    s[i] = a[i] - lo;
    if (s[i] % k != 0) {
      ans = -1;
      temp = 0;
      break;
    }
  }
  if (temp != 0) {
    for (long long int i = 0; i < n; i++) {
      ans += s[i] / k;
    }
  }
  cout << ans;
}
