#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t, n, m, i, j, k, sum = 0;
  cin >> n;
  vector<long long int> a(n);
  set<long long int> b;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b.insert(a[i]);
  }
  vector<long long int> temp;
  temp.assign(b.begin(), b.end());
  if (temp.size() == 1) {
    cout << "0\n";
    return 0;
  }
  t = temp.size();
  if (t == 2) {
    if ((temp[1] + temp[0]) % 2 == 0) {
      cout << temp[1] - (temp[1] + temp[0]) / 2 << '\n';
      return 0;
    }
  }
  if (t > 3) {
    cout << "-1\n";
    return 0;
  }
  long long int init = temp[t - 1] - temp[t - 2];
  for (i = temp.size() - 1; i > 0; i--) {
    k = temp[i] - temp[i - 1];
    if (k != init) {
      cout << "-1\n";
      return 0;
    }
    init = k;
  }
  cout << k << '\n';
  return 0;
}
