#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int min = a[0], max = a[0];
  for (int i = 1; i < n; ++i) {
    if (a[i] < min) min = a[i];
    if (a[i] > max) max = a[i];
  }
  if ((max - min) % 2) {
    bool can = true;
    for (int i = 0; i < n && can; ++i) {
      if (a[i] != max && a[i] != min) can = false;
    }
    if (can)
      cout << max - min << endl;
    else
      cout << -1 << endl;
  } else {
    int d, g;
    d = (max - min) / 2;
    g = max - d;
    bool can = true;
    for (int i = 0; i < n && can; ++i) {
      if (a[i] > g) {
        if (a[i] - d != g) can = false;
      } else if (a[i] < g) {
        if (a[i] + d != g) can = false;
      }
    }
    if (can)
      cout << d << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
