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