#include <bits/stdc++.h>
int main() {
  int n;
  long long k;
  std::cin >> n >> k;
  std::vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  std::sort(a.begin(), a.end(), std::greater<long long>());
  long long answer = 0;
  for (int i = 0; i < n - 1; i++) {
    if ((a[i] - a.back()) % k == 0) {
      answer += (a[i] - a.back()) / k;
    } else {
      std::cout << -1;
      return 0;
    }
  }
  std::cout << answer;
}
