#include <bits/stdc++.h>
using namespace std;
const int c = 1E9 + 7;
vector<int> arr;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    arr.emplace_back(x);
  }
  sort(arr.begin(), arr.end());
  int mx = arr[0];
  long long cnt = 0;
  for (int i = 1; i < n; ++i) {
    if ((arr[i] - mx) % m != 0) {
      cout << -1;
      return 0;
    } else
      cnt += (arr[i] - mx) / m;
  }
  cout << cnt;
  cin >> cnt;
  return 0;
}
