#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long as;
  sort(a, a + n);
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  long long val = a[0];
  long long c = 0;
  for (int i = 1; i < n; i++) {
    as = abs(val - a[i]);
    if (as % k != 0) {
      cout << "-1" << endl;
      return 0;
    }
    c += as / k;
  }
  cout << c << endl;
  return 0;
}
