#include <bits/stdc++.h>
const unsigned int M = 1000000007;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long a, b, c, n, sum = 0, flag = 0;
  cin >> a >> b;
  unsigned long long arr[a];
  for (int i = 0; i < a; i++) cin >> arr[i];
  sort(arr, arr + a);
  for (int i = 1; i < a; i++) {
    if ((arr[i] - arr[0]) % b == 0)
      sum += (arr[i] - arr[0]) / b;
    else {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << -1;
  else
    cout << sum;
}
