#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n;
    cin>>n;
    ll stones[n+1],x=0;
    for(int i=1;i<=n;i++){
    	cin>>stones[i];
    	if(i>2)
    		x=(x^stones[i]);
	}
	ll s=stones[1]+stones[2]-x;
	ll d=stones[1];
	if(s%2==1||s<0){
		cout<<-1<<endl;
		return 0;
	} 
	s/=2;
	if((s&x)>0||s>d){
		cout<<-1<<endl;
		return 0;
	}
	stones[1]=stones[2]=s;
	for(int i=40;i>=0;i--){
		ll p=(1LL<<i);
		if((p&x)>0){
			if(stones[1]+p>d)
				stones[2]+=p;
			else
				stones[1]+=p;
		}
	}
	ll ans;
	if(stones[1]==0)
		ans=-1;
	else
		ans=d-stones[1];
	cout<<ans<<endl;
}