#include <bits/stdc++.h>
using namespace std;
int v[100010];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int low = 1000000001;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    low = min(low, v[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n && ans != -1; i++) {
    if ((v[i] - low) % k == 0) {
      ans += (v[i] - low) / k;
    } else
      ans = -1;
  }
  cout << ans << endl;
  return 0;
}
