#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
long long INF = 1e18;
int n, k, a[100005];
int solve() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 1; i < n; i++) {
    if (a[0] % k != a[i] % k) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (a[i] - a[0]) / k;
  }
  cout << ans << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
