#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<int> inp;
  for (int i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    inp.push_back(temp);
  }
  sort((inp).begin(), (inp).end());
  long long lowest = inp[0];
  int flag = 0;
  long long time = 0;
  for (int i = 1; i < n; i++) {
    if ((inp[i] - lowest) % k == 0) {
      time += (inp[i] - lowest) / k;
    } else {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    cout << "-1";
  else
    cout << time;
}
