#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << 0;
    exit(0);
  }
  long long c = 10000000000000;
  for (i = 0; i < n; i++) {
    if (a[i] < c) {
      c = a[i];
    }
  }
  long long r = a[0] % m;
  long long h = 0;
  for (i = 0; i < n; i++) {
    if (a[i] % m == r) {
      h++;
    }
  }
  if (h != n) {
    cout << "-1";
    exit(0);
  }
  i = 0;
  long long count = 0;
  for (i = 0; i < n; i++) {
    long long e = 0;
    e = (a[i] / m - c / m);
    count += e;
  }
  cout << count;
  return 0;
}
