#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  set<int> s;
  for (int i = 0; i < n; i++) {
    s.insert(a[i]);
  }
  if (s.size() > 3) {
    cout << "-1\n";
    return 0;
  }
  if (s.size() == 1) {
    cout << "0\n";
    return 0;
  }
  if (s.size() == 2) {
    int a, b;
    a = *s.begin();
    b = *s.rbegin();
    if ((b - a) % 2 == 0) {
      cout << (b - a) / 2 << "\n";
    } else {
      cout << b - a;
    }
    return 0;
  }
  vector<int> ans(3, 0);
  int ind = 0;
  for (auto i : s) {
    ans[ind] = i;
    ind++;
  }
  if (ans[1] - ans[0] != ans[2] - ans[1]) {
    cout << "-1\n";
    return 0;
  } else {
    cout << ans[1] - ans[0] << "\n";
    return 0;
  }
}
