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