#include <bits/stdc++.h>
const int OO = (int)1e9 + 7;
using namespace std;
int A[(int)2e5 + 10];
int main() {
  long long sum = 0;
  int n, k, Mn = OO;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    Mn = min(Mn, A[i]);
  }
  for (int i = 0; i < n; i++) {
    sum += (A[i] - Mn);
    if ((A[i] - Mn) % k != 0) {
      cout << -1;
      return 0;
    }
  }
  if (sum % k != 0)
    cout << -1;
  else
    cout << sum / k;
}
