#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, c, m = 1e9, k, ans = 0;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m = min(m, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if ((a[i] - m) % k != 0) {
      cout << -1;
      return 0;
    }
    ans += (a[i] - m) / k;
  }
  cout << ans;
  return 0;
}
