#include <bits/stdc++.h>
using namespace std;
long long b, c, d, ans, a[100000], n, k, mi = 1000000000000;
int main() {
  cin >> n >> k;
  for (long long u = 0; u < n; u++) {
    cin >> a[u];
    mi = min(mi, a[u]);
  }
  for (long long i = 0; i < n; i++) {
    c += (abs(a[i] - mi) / k);
    if (abs(a[i] - mi) % k) {
      cout << "-1";
      return 0;
    }
  }
  cout << c;
  return 0;
}
