#include <bits/stdc++.h>
using namespace std;
struct code {
  int x, y;
};
bool comp(code a, code b) { return a.x < b.x or (a.x == b.x and a.y < b.y); }
const int MX = 2e5 + 10;
int a[MX], n, m, ok;
int main() {
  int n, k;
  cin >> n >> k;
  ok = 1e9 + 7;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ok = min(ok, a[i]);
  }
  int64_t sum = 0;
  for (int i = 1; i <= n; i++) {
    int now = a[i] - ok;
    if (now % k != 0) {
      cout << -1;
      return 0;
    }
    sum += now / k;
  }
  cout << sum;
}
