#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  scanf("%d", &n);
  long long a[n], k, sum = 0;
  cin >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = 1; i < n; i++) {
    a[i] -= a[0];
    if (a[i] % k != 0) {
      cout << -1;
      return 0;
    }
    sum += a[i] / k;
  }
  cout << sum;
}
