#include <bits/stdc++.h>
using namespace std;
long long ae[100200];
int main() {
  long long a, n, k;
  cin >> n >> k;
  long long mini = 2399348943, c = 0, b = 1, b2 = 1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ae[i] = a;
    mini = min(a, mini);
  }
  for (int i = 0; i < n; i++) ae[i] = (ae[i] - mini);
  for (int i = 0; i < n; i++) {
    if (!(ae[i] % k)) {
      c += ae[i] / k;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", c);
  return 0;
}
