#include <bits/stdc++.h>
using namespace std;
template <class T>
using lim = numeric_limits<T>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int rem = a[0] % k;
  bool possible = true;
  long long total = a[0];
  long long smol = a[0];
  for (int i = 1; i < n; i++) {
    possible &= rem == a[i] % k;
    total += a[i];
    if (smol > a[i]) smol = a[i];
  }
  total -= smol * n;
  if (possible)
    cout << total / k << "\n";
  else
    cout << -1 << "\n";
}
