#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int arr[n];
  for (long long int i = 0; i < n; ++i) cin >> arr[i];
  unordered_map<long long int, long long int> m;
  for (long long int i = 0; i < n; ++i) {
    if (m.find(arr[i]) == m.end()) {
      m[arr[i]] = 1;
    }
  }
  vector<long long int> v;
  for (auto x : m) {
    v.push_back(x.first);
  }
  if (v.size() > 3) {
    cout << -1 << endl;
  } else if (v.size() == 3) {
    sort(v.begin(), v.end());
    if (abs(v[0] - v[1]) == abs(v[1] - v[2])) {
      cout << abs(v[0] - v[1]) << endl;
    } else {
      cout << -1 << endl;
    }
  } else if (v.size() == 2) {
    if (abs(v[0] - v[1]) % 2 == 0) {
      cout << (abs(v[0] - v[1]) / 2) << endl;
    } else {
      cout << abs(v[0] - v[1]) << endl;
    }
  } else {
    cout << 0 << endl;
  }
  return 0;
}
