#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, mini = 1000000005, sum = 0;
  cin >> n >> k;
  long long A[n];
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    mini = min(A[i], mini);
  }
  for (int i = 0; i < n; ++i) {
    A[i] = A[i] - mini;
    if (A[i] % k == 0) {
      if (A[i] != 0) sum += A[i] / k;
    } else {
      sum = -1;
      break;
    }
  }
  cout << sum << endl;
  return 0;
}
