#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
const int INF = int(2e9);
long long n, k, a[N], ans = 0, mini = (1e16);
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < mini) mini = a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] - mini != 0 && (a[i] - mini) % k != 0) {
      cout << -1;
      exit(0);
    } else {
      ans += (a[i] - mini) / k;
    }
  }
  cout << ans;
  return 0;
}
