#include <bits/stdc++.h>
using namespace std;
long long arr[1000000];
long long menor = 1e9;
int main() {
  bool t = true;
  int ci = 0, cc = 0, c = 0;
  long long n, m, sum = 0, total = 0;
  scanf("%lld%lld", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    if (arr[i] < menor) {
      menor = arr[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] != menor) {
      sum = arr[i] - menor;
      if (sum < m) {
        cc++;
      } else if (sum % m == 0) {
        total += sum / m;
        c++;
      }
    }
    if (menor == arr[i]) {
      ci++;
    }
  }
  if (ci == n) {
    printf("0");
  } else if (cc > c) {
    printf("-1");
  } else if (c + ci == n) {
    printf("%lld", total);
  } else {
    printf("-1");
  }
  return 0;
}
