#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100024], mina = 100000000000000000, res = 0;
;
void Init() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mina = min(mina, a[i]);
  }
}
void Solve() {
  for (int i = 1; i <= n; i++) {
    if ((a[i] - mina) % k == 0) {
      res += (a[i] - mina) / k;
    } else {
      cout << -1;
      return;
    }
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  Init();
  Solve();
}
