#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int min = 1000000000;
  long long sum = 0;
  vector<int> a;
  for (long long i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    a.push_back(temp);
    min = ((min) > (temp) ? (temp) : (min));
  }
  for (long long i = 0; i < n; i++) {
    if ((a[i] - min) % k != 0) {
      cout << -1 << endl;
      return 0;
    }
    sum += (a[i] - min) / k;
  }
  cout << sum << endl;
  return 0;
}
