#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return abs(b);
  return gcd(b % a, a);
}
int main() {
  long long int n, k, arr[1000000], i = 0, div = -1, sum = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  for (i = 1; i < n; i++) {
    arr[i] = arr[i] - arr[0];
    if (arr[i] != 0 && arr[i] % k == 0) {
      div = arr[i] / k;
      sum = sum + div;
    }
    if (arr[i] % k != 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (sum == 0)
    cout << 0 << endl;
  else
    cout << sum << endl;
  return 0;
}
