#include <bits/stdc++.h>
using namespace std;
void shikhar7s(long long int cas) {
  long long int n, i;
  cin >> n;
  long long int a[n];
  vector<long long int> v;
  map<long long int, long long int> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (m.count(a[i]) == 0) v.push_back(a[i]);
    m[a[i]]++;
  }
  long long int vs = (long long int)v.size();
  sort(v.begin(), v.end());
  if (vs > 3)
    cout << -1;
  else if (vs == 3) {
    if (v[1] - v[0] == v[2] - v[1])
      cout << v[1] - v[0];
    else
      cout << -1;
  } else if (vs == 2) {
    if ((v[1] - v[0]) % 2 == 0)
      cout << (v[1] - v[0]) / 2;
    else
      cout << v[1] - v[0];
  } else {
    cout << 0;
  }
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  long long int t = 1;
  long long int cas = 1;
  while (cas <= t) {
    shikhar7s(cas);
    cas++;
  }
  return 0;
}
