#include <bits/stdc++.h>
using namespace std;
int main() {
  set<long long> s;
  long long n, i;
  cin >> n;
  long long arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    s.insert(arr[i]);
  }
  if (s.size() > 3) {
    cout << -1 << endl;
  } else if (s.size() == 1) {
    cout << 0;
  } else if (s.size() == 3) {
    sort(arr, arr + n);
    long long val = 0;
    long long sum = arr[n - 1] - arr[0];
    long long mid = 0;
    for (i = 0; i < n; i++) {
      if (arr[0] != arr[i] && arr[n - 1] != arr[i]) {
        mid = arr[i];
        val = mid - arr[0];
        break;
      }
    }
    if (mid == 0) {
      cout << -1;
    } else {
      for (i = 0; i < n; i++) {
        if (arr[i] == mid || arr[i] + val == mid || arr[i] - val == mid) {
        } else {
          cout << -1;
          return 0;
        }
      }
      cout << val;
    }
  } else if (s.size() == 2) {
    sort(arr, arr + n);
    long long sum = arr[n - 1] - arr[0];
    if (sum % 2 == 0) {
      cout << sum / 2;
    } else {
      cout << sum;
    }
    return 0;
  }
}
