#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
long long n, k;
long long arr[100010];
int main() {
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);
  cin >> n >> k;
  for (int(i) = (0); i < (n); ++(i)) cin >> arr[i];
  long long curr = arr[0] % k;
  for (int(i) = (1); i < (n); ++(i))
    if (arr[i] % k != curr) {
      cout << -1 << endl;
      return 0;
    }
  long long mn = arr[0] / k;
  for (int(i) = (1); i < (n); ++(i)) {
    mn = min(mn, arr[i] / k);
  }
  long long ans = 0;
  for (int(i) = (0); i < (n); ++(i)) {
    ans += arr[i] / k - mn;
  }
  cout << ans << endl;
  return 0;
}
