#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int G = 0;
  int n, k, mn = 1e9 + 1;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    mn = min(a[i], mn);
  }
  for (int i = 0; i < n; i++) {
    if ((a[i] - mn) % k != 0) {
      cout << -1;
      return 0;
    }
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int dif = a[i] - mn;
    sum += dif / k;
  }
  cout << sum << endl;
  return 0;
}
