#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  ll x=0;
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    if(i>1) x^=a[i];
  }
  ll s=a[0]+a[1];
  ll d=(s-x)/2;
  if(s-x<0||(s-x)%2||d&x||d>a[0]) {
    cout << -1 << endl;
    return 0;
  }
  ll ans=d;
  for(ll i=(1LL<<61);i;i>>=1) {
    if(!(i&x)) continue;
    if(ans+i<a[0]) ans+=i;
  }
  if(ans) cout << a[0]-ans << endl;
  else cout << -1 << endl;
}