#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  int i;
  int flag = 0;
  cin >> a[0];
  int rem = a[0] % k;
  int min = a[0];
  for (i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] % k != rem) flag = 1;
    if (a[i] < min) min = a[i];
  }
  if (flag == 1) {
    cout << -1 << endl;
    return 0;
  }
  long long sum{};
  for (i = 0; i < n; i++) sum += (a[i] - min) / k;
  cout << sum;
  return 0;
}
