#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int N;
    cin>>N;
    vector<ll> A(N);
    ll now=0;
    rep(i,N){
        cin>>A.at(i);
        now=now^A.at(i);
    }
    if(now==0){cout<<0<<endl;return 0;}
    now=now^A.at(0);
    now=now^A.at(1);
    ll p=A.at(0)+A.at(1)-now;
    if(p%2){cout<<-1<<endl;return 0;}
    p/=2;
    //cout<<p<<" "<<now<<endl;
    if(p>=A.at(0) || p&now){cout<<-1<<endl;return 0;}
    for(int i=42;i>=0;i--){
        if(1ll<<i & now){
            if((p + (1ll<<i)) <A.at(0)){
                p+= (1ll<<i);
            }
        }
    }
    if(p==0){cout<<-1<<endl;return 0;}
    cout<<A.at(0)-p<<endl;
}