#include <bits/stdc++.h>
using namespace std;
long long v[100005];
int main() {
  long long n, k, cnt = 0, temp, mn = INFINITY;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (v[i] < mn) mn = v[i];
  }
  for (int i = 0; i < n; i++) {
    temp = v[i] - mn;
    if (temp % k == 0)
      cnt += temp / k;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << cnt << endl;
  return 0;
}
