#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100010];
  int n, k, i, minx;
  long long ans;
  bool flag;
  cin >> n >> k;
  minx = 0x3f3f3f3f;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] < minx) minx = a[i];
  }
  ans = 0;
  flag = true;
  for (i = 1; i <= n; i++) {
    if ((a[i] - minx) % k) flag = false;
    ans += (a[i] - minx) / k;
  }
  if (flag)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
