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