#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 100005;
long long a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  set<int> b;
  long long mn = mod;
  for (int i = 1; i <= (n); ++i) {
    cin >> a[i];
    b.insert(a[i] % k);
    mn = min(mn, a[i]);
  }
  if (b.size() != 1) {
    cout << -1 << endl;
    return 0;
  }
  long long res = 0;
  for (int i = 1; i <= (n); ++i) {
    res += (a[i] - mn) / k;
  }
  cout << res << endl;
  return 0;
}
