#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double PI = 3.141592653589793;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  long long int ans = mod;
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i <= 1000; i++) {
    set<int> s;
    int r = 0;
    for (int j = 0; j < n; j++) {
      s.insert(abs(v[j] - i));
      if (v[j] != i) r = j;
    }
    if (s.size() == 1 || (s.size() == 2 && *s.begin() == 0))
      ans = min(ans, (long long int)abs(v[r] - i));
  }
  if (ans == mod)
    cout << -1;
  else
    cout << ans;
  cerr << "Time Lapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << '\n';
  return 0;
}
