#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  vector<long long int> v;
  cin >> n >> k;
  long long int r;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    v.push_back(a);
  }
  r = v[0] % k;
  long long int mn = 10000000000000;
  for (long long int i = 0; i < n; i++) {
    if (v[i] % k != r) {
      cout << "-1\n";
      return 0;
    }
    mn = min(mn, v[i]);
  }
  long long int count = 0;
  for (int i = 0; i < n; i++) {
    count += (v[i] - mn) / k;
  }
  cout << count << "\n";
  return 0;
}
