#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const long long MOD = 1e9 + 7;
long long a[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  long long k, mn = 1e10;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mn = min(mn, a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    long long d = a[i] - mn;
    if (d && d % k != 0) {
      cout << -1;
      return 0;
    }
    ans += d / k;
  }
  cout << ans;
}
