#include <bits/stdc++.h>
using namespace std;
int n, m, k, a[100000];
long long ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  cin >> a[0];
  m = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    m = min(m, a[i]);
  }
  for (int i = 0; i < n; i++)
    if (!((a[i] - m) % k))
      ans += (a[i] - m) / k;
    else {
      cout << -1 << endl;
      return 0;
    }
  cout << ans << endl;
  return 0;
}
