#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
  int n, k;
  cin >> n >> k;
  int mini = 2147483647;
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]), mini = min(mini, arr[i]);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int diff = arr[i] - mini;
    if (diff % k) {
      cout << -1;
      return 0;
    }
    ans += diff / k;
  }
  cout << ans;
  return 0;
}
