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