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