#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  int minimum = INT_MAX;
  vector<int> v(n);
  cin >> v[0];
  for (int i = 1; i < n; ++i) {
    cin >> v[i];
    if (abs(v[i] - v[i - 1]) % k != 0) {
      cout << -1;
      return 0;
    } else {
      minimum = min(minimum, min(v[i], v[i - 1]));
    }
  }
  for (int i = 0; i < n; ++i) {
    ans += (v[i] - minimum) / k;
  }
  cout << max((long long)0, ans);
  return 0;
}
