#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  scanf("%lld", &n);
  scanf("%lld", &k);
  long long int a[n];
  for (__typeof(n) i = 0 - (0 > n); i != n - (0 > n); i += 1 - 2 * (0 > n))
    scanf("%lld", &a[i]);
  sort(a, a + n);
  long long int ans = 0;
  for (__typeof(n) i = 1 - (1 > n); i != n - (1 > n); i += 1 - 2 * (1 > n)) {
    long long int diff = a[i] - a[0];
    if (diff % k) {
      printf("%d\n", -1);
      return 0;
    }
    ans += diff / k;
  }
  printf("%lld\n", ans);
  return 0;
}
