#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  vector<long long> vec;
  long long n, mn = INT_MAX, mx = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long t;
    cin >> t;
    vec.push_back(t);
    mn = min(mn, t);
    mx = max(mx, t);
  }
  long long dif = mx - mn;
  if (dif % 2 == 0) {
    long long mid = mn + (dif / 2), aor = dif / 2;
    for (int i = 0; i < n; i++) {
      if (vec[i] < mid)
        vec[i] += aor;
      else if (vec[i] > mid)
        vec[i] -= aor;
    }
    for (int i = 0; i < n; i++) {
      if (vec[i] != mid) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << aor << endl;
  } else {
    long long f = mx - mn;
    for (int i = 0; i < n; i++) {
      if (vec[i] == mx)
        continue;
      else
        vec[i] += dif;
    }
    for (int i = 0; i < n; i++) {
      if (vec[i] != mx) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << dif << endl;
  }
  return 0;
}
