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