#include <bits/stdc++.h>
using namespace std;
int n, k;
long long A[100005];
long long Sum = 0, r, mn = 2000000000;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    Sum += A[i];
    mn = min(mn, A[i]);
  }
  for (int i = 1; i <= n; i++) {
    if ((A[i] - mn) % k) {
      cout << -1;
      return 0;
    }
  }
  r = (Sum - n * mn) / k;
  if (r * k != Sum - n * mn)
    cout << -1;
  else
    cout << r;
  return 0;
}
