#include <bits/stdc++.h>
using namespace std;
void addmod(int &a, long long b) {
  a = (a + b);
  if (a >= 1000000007) a -= 1000000007;
}
void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
template <class T>
bool domin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool domax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int gi() {
  int a;
  scanf("%d", &a);
  return a;
}
long long gll() {
  long long a;
  scanf("%lld", &a);
  return a;
}
int main() {
  long long n = gi(), k = gi(), ans = 0;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = gi();
  }
  sort(a.begin(), a.end());
  for (int i = 1; i < n; i++) {
    long long diff = a[i] - a[0];
    if (diff % k) {
      cout << -1 << endl;
      return 0;
    }
    ans += diff / k;
  }
  cout << ans << endl;
  return 0;
}
