#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  long long min = INT_MAX;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (v[i] < min) {
      min = v[i];
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if ((v[i] - min) % k == 0) {
      ans += (v[i] - min) / k;
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans;
}
