#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
long long a[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, mn = 1e18;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mn = min(mn, a[i]);
  }
  vector<long long> check;
  for (long long i = 0; i < n; i++) check.push_back(a[i] % k);
  for (long long i = 1; i < n; i++)
    if (check[i] != check[0]) return cout << -1, 0;
  long long sum = 0;
  for (long long i = 0; i < n; i++) sum += a[i] - mn;
  cout << sum / k;
  return 0;
}
