#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int n;
ll a[maxn];
void GG()
{
    cout<<-1<<endl; exit(0);
}
int main()
{
    fastio();
    cin>>n;
    rep(i,1,n) cin>>a[i];
    ll x = 0;
    rep(i,3,n) x ^= a[i];
    ll t = a[1] + a[2];
    ll b = (t-x)>>1;
    if(t<x || ((t-x)&1) || (b&x)) GG();
    vector<ll> g;
    rep(i,0,62){
        if ((x>>i)&1){
            ll tmp = 1LL<<i;
            g.pb(tmp);
        }
    }
    reverse(g.begin(),g.end());
    for(ll bb:g) if(b+bb<=a[1]) b+=bb;
    if(b>0 && b<=a[1])cout<<a[1]-b<<endl;
    else GG();
    return 0;
}
