#include <bits/stdc++.h>
using namespace std;
void solve() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  long long result = 0;
  cin >> n;
  cin >> k;
  vector<int> aa(n);
  for (int i = 0; i < n; i++) {
    cin >> aa[i];
  }
  if (n == 1) {
    cout << 0 << endl;
  } else {
    sort(aa.begin(), aa.end());
    for (int i = 0; i < n; i++) {
      if ((aa[i] - aa[0]) % k != 0) {
        cout << -1 << endl;
        return 0;
      }
      result += (aa[i] - aa[0]) / k;
    }
    cout << result << endl;
  }
}
