#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long res = 0, mi;
  int n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  mi = *min_element(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    if ((a[i] - mi) % k != 0) {
      cout << -1 << endl;
      return 0;
    }
    res += (a[i] - mi) / k;
  }
  cout << res << endl;
  return 0;
}
