#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int arr[MAX];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int mn = 1e9 + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    mn = min(mn, arr[i]);
  }
  int flg = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (((arr[i] - mn) % k) != 0) {
      flg = -1;
      break;
    } else {
      ans += (arr[i] - mn) / k;
    }
  }
  if (flg == -1) {
    printf("%d\n", flg);
  } else {
    printf("%lld\n", ans);
  }
  return 0;
}
