#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, cnt = 0, temp, mn = INFINITY, v[100005];
  scanf("%I64d%I64d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &v[i]);
    if (v[i] < mn) mn = v[i];
  }
  for (int i = 0; i < n; i++) {
    if (abs(v[i] - mn) % k == 0)
      cnt += abs(v[i] - mn) / k;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << cnt << endl;
  return 0;
}
