#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, k;
  cin >> n >> k;
  int a[n];
  cin >> a[0];
  int m = a[0];
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
    if (abs(a[i - 1] - a[i]) % k != 0) {
      cout << "-1";
      return 0;
    }
    m = min(m, a[i]);
  }
  unsigned long long t = 0;
  for (int i = 0; i < n; ++i) {
    t += abs(a[i] - m) / k;
  }
  cout << t;
  return 0;
}
