#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int mod = 1e9 + 7;
long long n, k, arr[MAX], ans = 0;
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  if (n == 1) {
    cout << 0;
    exit(0);
  }
  bool moded = true;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  long long modu = arr[0] % k;
  for (int i = 0; i < n; i++)
    if (arr[i] % k != modu) moded = false;
  if (moded)
    for (int i = 0; i < n; i++) ans += (arr[i] - arr[0]) / k;
  else
    ans = -1;
  cout << ans;
  return 0;
}
