#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
int main() {
  long long n, k, a[100005], s, i, p, m;
  while (cin >> n >> k) {
    bool f = 0;
    for (i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    p = a[0];
    s = 0;
    for (i = 1; i < n; i++) {
      m = a[i] - p;
      if (m % k == 0)
        s = s + (m / k);
      else {
        f = 1;
        break;
      }
    }
    if (f == 0)
      cout << s << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}
