#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  a.resize(n);
  int Min = 1500000000;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] < Min) Min = a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if ((a[i] - Min) % k == 0)
      ans += (a[i] - Min) / k;
    else {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  char r;
  cin >> r;
  if (r == 'r') main();
  return 0;
}
