#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100001];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] % k != a[0] % k) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int p = a[0];
  for (int i = 0; i < n; i++) {
    p = min(p, a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (a[i] - p) / k;
  }
  cout << ans << endl;
  return 0;
}
