#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    if ((a[i] - a[1]) % k != 0) {
      puts("-1");
      exit(0);
    } else
      ans += (a[i] - a[1]) / k;
  printf("%I64d\n", ans);
  return 0;
}
