#include <bits/stdc++.h>
using namespace std;
int N;
bool valid(int P, int d, vector<int> guess) {
  if (P >= N) {
    return true;
  }
  if (P == 0) {
    if (valid(P + 1, d, guess)) return true;
    guess[P] -= d;
    if (valid(P + 1, d, guess)) return true;
    guess[P] += d;
    guess[P] += d;
    if (valid(P + 1, d, guess)) return true;
    guess[P] -= d;
  } else {
    if (guess[P] == guess[P - 1]) {
      if (valid(P + 1, d, guess)) return true;
    } else if ((guess[P] - d) == guess[P - 1]) {
      guess[P] -= d;
      if (valid(P + 1, d, guess)) return true;
      guess[P] += d;
    } else if ((guess[P] + d) == guess[P - 1]) {
      guess[P] += d;
      if (valid(P + 1, d, guess)) return true;
      guess[P] -= d;
    }
  }
  return false;
}
int main() {
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V[i];
  for (int d = 0; d <= 100; d++) {
    if (valid(0, d, V)) {
      cout << d << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
