#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void maximize(T &x, U y) {
  if (x < y) x = y;
}
template <class T, class U>
void minimize(T &x, U y) {
  if (x > y) x = y;
}
template <class T>
T Abs(T x) {
  return (x < 0 ? -x : x);
}
template <class T>
T safe_sqrt(T x) {
  return sqrt(max(x, (T)0));
}
template <class T, class U, class V>
T addmod(T x, U k, V __base) {
  return ((x + k) % __base + __base) % __base;
}
template <class T, class U, class V>
T submod(T x, U k, V __base) {
  return ((x - k) % __base + __base) % __base;
}
template <class T, class U, class V>
T mul(T x, U y, V __base) {
  return (long long)x * y % __base;
}
const int N = 1e5 + 5;
long long a[N];
int n, k;
long long sum = 0;
int main(void) {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int minn = *min_element(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if ((a[i] - minn) % k) puts("-1"), exit(0);
    sum += 1ll * (a[i] - minn) / k;
  }
  cout << sum;
}
