#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long N = 1e5 + 1;
const long long mod = 1e8 + 0;
const long double eps = 1E-7;
long long n, k;
long long a[N], ans;
long long mn = INF;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mn = min(mn, a[i]);
  }
  for (int i = 1; i <= n; i++) {
    if ((a[i] - mn) % k != 0) {
      cout << -1;
      return 0;
    } else {
      ans += (a[i] - mn) / k;
    }
  }
  cout << ans << endl;
}
