#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n;
  cin >> k;
  int array[n];
  int min = 1000000001;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
    if (min > array[i]) {
      min = array[i];
    }
  }
  bool flag = true;
  long long result = 0;
  for (int i = 0; i < n; i++) {
    if ((array[i] - min) % k != 0) {
      flag = false;
      break;
    }
    result += (long long)(array[i] - min) / k;
  }
  if (flag) {
    cout << result << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
