#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i, arr[100008], kount = 0;
  scanf("%lld%lld", &n, &k);
  int flag = 0;
  for (i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
  }
  sort(arr, arr + n);
  for (i = 1; i < n; i++) {
    if ((arr[i] - arr[0]) % k != 0) {
      flag = 1;
      break;
    }
    kount += ((arr[i] - arr[0]) / k);
  }
  if (flag == 1)
    cout << -1 << endl;
  else
    cout << kount << endl;
}
