#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, z, s, d = 0, sum = 0, x[100000], i, b, mini = 1000000000;
  cin >> a >> b;
  for (i = 0; i < a; i++) {
    cin >> x[i];
    if (x[i] < mini) {
      mini = x[i];
    }
  }
  for (i = 0; i < a; i++) {
    if (x[i] > mini) {
      s = x[i] - mini;
      if (s % b == 0) {
        z = s / b;
        sum = sum + z;
      } else {
        d++;
        cout << "-1" << endl;
        break;
      }
    }
  }
  if (d == 0) {
    cout << sum << endl;
  }
  return 0;
}
