#include <bits/stdc++.h>
using namespace std;
int long long n, k, i, j, b[100005], minn = 1e9 + 8, ans;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> b[i];
    minn = min(minn, b[i]);
  }
  for (i = 1; i <= n; i++) {
    if ((b[i] - minn) % k) {
      cout << -1;
      return 0;
    }
    ans += (b[i] - minn) / k;
  }
  cout << ans << endl;
}
