#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int prices[n];
  for (long long int i = 0; i < n; i++) {
    cin >> prices[i];
  }
  long long int minimum = prices[0];
  long long int ans = 0;
  for (long long int i = 1; i < n; i++) {
    if (prices[i] < minimum) {
      minimum = prices[i];
    }
  }
  for (long long int i = 0; i < n; i++) {
    prices[i] -= minimum;
  }
  for (long long int i = 0; i < n; i++) {
    if (prices[i] % k != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long int i = 0; i < n; i++) {
    ans += prices[i] / k;
  }
  cout << ans << endl;
  return 0;
}
