#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
int32_t main() {
  long long t = 1, ca = 0;
  long long a, b, c, d, sum;
  while (t--) {
    long long n, k, mx = 1e18, x;
    cin >> n >> k;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    for (long long i = 0; i < n; i++) {
      if (i == 0) {
        x = a[i] % k;
      } else {
        if (x != a[i] % k) {
          cout << "-1"
               << "\n";
          return 0;
        }
      }
      mx = min(a[i], mx);
    }
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      ans += (a[i] - mx) / k;
    }
    cout << ans << "\n";
  }
  return 0;
}
