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