#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long a[maxn];
int main() {
  long long n, m, minn = 0x3f3f3f3f;
  scanf("%I64d%I64d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", a + i);
    minn = min(minn, a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if ((a[i] - minn) % m != 0) {
      return 0 * printf("-1\n");
    }
    ans += ((a[i] - minn)) / m;
  }
  printf("%I64d\n", ans);
  return 0;
}
