#include <bits/stdc++.h>
using namespace std;
int seq[100010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int minn = 1e9;
  for (int i = 0; i < n; i++) {
    scanf("%d", &seq[i]);
    minn = min(seq[i], minn);
  }
  bool possible = true;
  long long times = 0;
  for (int i = 0; i < n; i++) {
    if (seq[i] != minn) {
      int dif = seq[i] - minn;
      if (dif % k == 0) {
        times += (dif / k);
      } else {
        possible = false;
        break;
      }
    }
  }
  if (!possible) {
    printf("-1\n");
  } else {
    printf("%I64d\n", times);
  }
  return 0;
}
