#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, small = 1e9;
  long long c(0);
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] < small) small = arr[i];
  }
  for (int i = 0; i < n; i++) {
    if ((arr[i] - small) % k != 0) {
      cout << -1;
      return 0;
    } else
      c += (arr[i] - small) / k;
  }
  cout << c;
  return 0;
}
