#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int a[M];
int32_t main() {
  int n, k;
  cin >> n >> k;
  int MIN = 2e9;
  for (int i = 0; i < n; i++) cin >> a[i], ((MIN) = min((MIN), (a[i])));
  int p = a[0] % k;
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (a[i] % k != p)
      return cout << -1 << endl, 0;
    else
      ans += (long long)((a[i] - MIN) / k);
  return cout << ans << endl, 0;
}
