#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long int maxx(long long int a, long long int b) { return a > b ? a : b; }
long long int minn(long long int a, long long int b) { return a > b ? b : a; }
using namespace std;
int dx[] = {1, 1, 1, 0, 0, -1, -1, -1, 0};
int dy[] = {-1, 0, 1, 1, -1, 0, 1, -1, 0};
void boostIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int poww(long long int base, long long int exp) {
  base %= 1000000007;
  long long int result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % 1000000007;
    base = (base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}
vector<int> a[200];
bool pos[120][120], vis[120];
int n, m;
void dfs(int root) {
  vis[root] = 1;
  for (int i = 0; i < a[root].size(); i++) {
    if (!vis[a[root][i]]) dfs(a[root][i]);
  }
  return;
}
int comp() {
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ret++;
      dfs(i);
    }
  }
  return ret;
}
int main() {
  int n, k;
  cin >> n >> k;
  int mi = 1e9;
  long long int ans = 0;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
    mi = min(mi, x);
  }
  for (int i = 0; i < n; i++) {
    if ((a[i] - mi) % k == 0) {
      ans = ans + (a[i] - mi) / k;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
