// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/27/20 20:37:14
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int n; cin>>n;
  vector<ll> A(n); for (auto& a:A) cin>>a;
  auto solve = [&]() -> ll {
    ll X = n == 2 ? 0 : accumulate(A.begin()+2, A.end(), 0ll,
                                   [](ll a, ll b) {return a^b;});
    auto f = A[0];
    auto S = f+A[1];
    if (S < X or ((S-X)%2)==1) {
      return -1;
    }
    ll D = (S-X)/2;
    if (D & X or D > f) {
      return -1;
    }
    ll a = D;
    for (int i = 50; i >= 0; i--) {
      auto bit = 1ull<<i;
      if ((X&bit)==0)
        continue;
      if (ll(a|bit) <= f)
        a |= bit;
    }
    auto ans = f-a;

    return ans < f ? ans : -1;
  };
  cout << solve() << endl;

  return 0;
}
