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