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