#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, n, maxE = -9999999, minE = 9999999;
  vector<int> v;
  set<int> s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    if (a > maxE) {
      maxE = a;
    }
    if (a < minE) {
      minE = a;
    }
    s.insert(a);
  }
  if (s.size() == 2) {
    if ((maxE % 2) && !(minE % 2) || !(maxE % 2) && (minE % 2)) {
      cout << fabs(maxE - minE) << endl;
      return 0;
    }
  }
  int temp;
  int count = 0;
  while (true) {
    bool good = true;
    for (int i = 0; i < n; i++) {
      if (v[i] == minE) {
        temp = minE + count;
      }
      if (v[i] == maxE) {
        temp = maxE - count;
      }
      if (v[i] != maxE && v[i] != minE) {
        temp = v[i];
      }
      if (temp != maxE - count || temp != minE + count) {
        good = false;
      }
    }
    if (good) {
      cout << count << endl;
      break;
    }
    if ((minE + count) > (maxE - count)) {
      cout << -1 << endl;
      break;
    }
    count++;
  }
  return 0;
}
