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