#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
  int n, k, x = 1e9 + 7;
  long long j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x = min(x, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if ((a[i] - x) % k == 0) {
      j += ((a[i] - x) / k);
    } else {
      cout << -1;
      return 0;
    }
  }
  cout << j;
  return 0;
}
