#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int mn = a[0];
  for (int i = 0; i < n; ++i) {
    mn = min(mn, a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if ((a[i] - mn) % k != 0) {
      ans = -1;
    } else if (ans != -1) {
      ans += (a[i] - mn) / k;
    }
  }
  printf("%lld\n", ans);
}
