#include <bits/stdc++.h>
using namespace std;
const int size = 1e5 + 7;
long long a[size], ans = 2e9, res, val, n, k, i;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (!i)
      val = a[i] % k;
    else if (val != a[i] % k) {
      cout << -1;
      return 0;
    }
    ans = min(a[i], ans);
  }
  for (i = 0; i < n; i++) {
    val = a[i] - ans;
    res += val / k;
  }
  cout << res;
  return 0;
}
