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