#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[100000], n, k, s = 9999999999, z = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] <= s) s = a[i];
  }
  for (int i = 0; i < n; i++) {
    int h = (a[i] - s);
    if (a[i] != s) {
      if (h % k == 0)
        z += h / k;
      else {
        z = -1;
        break;
      }
    }
  }
  cout << z;
}
