#include <bits/stdc++.h>
const int MAX = 1e5 + 1000;
const int INF = 1e9 + 5;
using namespace std;
int n, k;
int a[MAX];
long long an;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  an = 0;
  for (int i = 2; i <= n; i++) {
    if ((a[i] - a[1]) % k) {
      printf("-1\n");
      return 0;
    } else {
      an += (long long)((a[i] - a[1]) / k);
    }
  }
  cout << an << "\n";
}
