#include <bits/stdc++.h>
using namespace std;
long long n, sum;
int k, x;
int main() {
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  bool f = true;
  sort(a, a + n);
  x = a[0] % k;
  for (int i = 1; i < n; i++) {
    if (a[i] % k != x) f = false;
  }
  if (f == false)
    cout << "-1";
  else {
    x = n / 2;
    for (int i = 0; i < n; i++) {
      sum += abs(a[0] - a[i]) / k;
    }
    cout << sum;
  }
  return 0;
}
