#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, step, smallest, count = 0;
  bool possible = true;
  cin >> n >> step;
  vector<long long> p(n);
  cin >> p[0];
  smallest = p[0];
  for (int i = 1; i < n; i++) {
    cin >> p[i];
    if (p[i] < smallest) {
      smallest = p[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if ((p[i] - smallest) % step != 0) {
      cout << -1 << endl;
      possible = false;
      break;
    } else {
      count += (p[i] - smallest) / step;
    }
  }
  if (possible == true) {
    cout << count << endl;
  }
  return 0;
}
