#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  int n, k, val, min = 1000000001;
  unsigned long long count = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> val;
    v.push_back(val);
    if (val < min) min = val;
  }
  for (int i = 0; i < n; i++) {
    if ((v[i] - min) % k == 0)
      count += (v[i] - min) / k;
    else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << count << endl;
  return 0;
}
