#include <bits/stdc++.h>
int a[100005];
int main() {
  int n, k;
  while (~scanf("%d %d", &n, &k)) {
    int min = 1e9 + 10;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i] < min) min = a[i];
    }
    long long ans = 0;
    bool f = true;
    for (int i = 1; i <= n; i++) {
      if ((a[i] - min) % k) {
        f = false;
        break;
      } else
        ans += (a[i] - min) / k;
    }
    if (f)
      printf("%I64d\n", ans);
    else
      printf("-1\n");
  }
}
