#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
const int MOD = 1e9 + 7;
const long long int INFL = (1LL << 62);
const long long int MODL = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  sort(arr, arr + n);
  int uniqueCount = 1;
  vector<int> unique;
  unique.push_back(arr[0]);
  for (int i = 1; i < n; ++i) {
    cout << arr[i] << " -- " << arr[i - 1] << endl;
    if (arr[i] != arr[i - 1]) {
      ++uniqueCount;
      cout << uniqueCount << endl;
      unique.push_back(arr[i]);
    }
  }
  if (uniqueCount > 3) {
    cout << -1 << endl;
    return 0;
  }
  if (uniqueCount == 1) {
    cout << 0 << endl;
    return 0;
  } else if (uniqueCount == 2) {
    if ((max(unique[0], unique[1]) - min(unique[0], unique[1])) % 2 == 0) {
      cout << ((max(unique[0], unique[1]) - min(unique[0], unique[1])) / 2)
           << endl;
    } else
      cout << abs(unique[0] - unique[1]) << endl;
    return 0;
  }
  int maxVal = unique[0], minVal = unique[0], sum = unique[0];
  for (int i = 1; i < unique.size(); ++i) {
    maxVal = max(unique[i], maxVal);
    minVal = min(unique[i], minVal);
    sum += unique[i];
  }
  int lastVal = sum - maxVal - minVal;
  if (abs(maxVal - lastVal) == abs(minVal - lastVal)) {
    cout << abs(maxVal - lastVal) << endl;
  } else
    cout << -1 << endl;
  return 0;
}
