#include <bits/stdc++.h>
using namespace std;
int n, v, e, p, q;
int m[100010];
string s, s1, s2;
long long ans = 1e9 + 7;
int main() {
  cin >> n >> v;
  for (int i = 1; i <= n; i++) {
    cin >> m[i];
    ans = min(ans, 1ll * m[i]);
  }
  for (int i = 1; i <= n; i++) {
    m[i] -= ans;
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += m[i] / v;
    m[i] = m[i] % v;
  }
  for (int i = 1; i < n; i++) {
    if (m[i] != m[i + 1]) {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
}
