#include <bits/stdc++.h>
using namespace std;
void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
int main() {
  fastInOut();
  int n, k;
  cin >> n >> k;
  long long mi = 100000000000000;
  int arr[n];
  bool f = true;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] < mi) mi = arr[i];
  }
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] != mi) {
      if ((arr[i] - mi) % k != 0) {
        cout << -1;
        return 0;
      }
      cnt += (arr[i] - mi) / k;
    }
  }
  cout << cnt;
  return 0;
}
