#include <bits/stdc++.h>
int main(int argc, char* argv[]) {
  long long n, k;
  std::cin >> n;
  std::cin >> k;
  std::vector<long long> arr(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> arr[i];
  }
  long long num = 0;
  auto it = std::min_element(arr.begin(), arr.end());
  for (auto a : arr) {
    if ((a - *it) % k != 0) {
      std::cout << std::to_string(-1);
      return 0;
    } else
      num += (a - *it) / k;
  }
  std::cout << std::to_string(num);
  return 0;
}
