#include <bits/stdc++.h>
using namespace std;
const int N = 150002;
long long a[100200];
int main() {
  long long n, k, m = 1000100000, x = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < m) m = a[i];
  }
  for (int i = 0; i < n && x >= 0; i++) {
    if ((a[i] - m) % k == 0)
      x += (a[i] - m) / k;
    else
      x = -1;
  }
  cout << x;
  return 0;
}
