#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3fLL;
int a[100010];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int mini = inf;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    mini = min(mini, a[i]);
  }
  long long aux = 0;
  bool pode = true;
  for (int i = 0; i < n; i++) {
    aux += (a[i] - mini) / k;
    if ((a[i] - mini) % k != 0) pode = false;
  }
  if (pode)
    printf("%I64d\n", aux);
  else
    printf("-1\n");
  return 0;
}
