#include <bits/stdc++.h>
using namespace std;
std::clock_t __start;
double __duration;
void start_timer() { __start = std::clock(); }
void print_timer() {
  __duration = (std::clock() - __start) / (double)CLOCKS_PER_SEC;
  std::cout << "Duration (msec): " << __duration * 1000 << '\n';
}
template <class T>
T min_(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
T max_(T a, T b) {
  return (a > b ? a : b);
}
double EPS = 1e-16;
bool eq_(const double& lhs, const double& rhs) {
  return (fabs(lhs - rhs) < EPS);
}
const int INF = int(2e9);
const long long INF_LL = LLONG_MAX;
const long long MOD = 1e9 + 7;
const int MAX_N = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  long long min_num = A[0];
  long long res = 0;
  for (int i = 1; i < N; ++i) {
    long long diff = A[i] - min_num;
    if (diff % K == 0)
      res += diff / K;
    else {
      res = -1;
      break;
    }
  }
  cout << res << '\n';
  return 0;
}
