#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, i, sum = 0, flag = 0, m = 10000000000, c;
  cin >> n >> k;
  long long int ara[n];
  for (i = 0; i < n; i++) {
    cin >> ara[i];
    if (ara[i] < m) {
      m = ara[i];
    }
  }
  for (i = 0; i < n; i++) {
    c = ara[i] - m;
    if (c % k == 0) {
      sum += c / k;
    } else {
      flag = 1;
      break;
    }
  }
  if (flag == 1) {
    cout << "-1";
  } else {
    cout << sum;
  }
  return 0;
}
