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

int main(){
  ll n,x=0;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i>1)x^=a[i];
  }
  ll s=a[0]+a[1];
  if(s<x || (s-x)%2!=0){cout<<-1<<endl;return 0;}
  ll d=(s-x)/2;
  if(d>a[0]){cout<<-1<<endl;return 0;}
  for(ll i=0;i<42;i++){
    if(((d>>i)&1)==1 && ((x>>i)&1)==1){cout<<-1<<endl;return 0;}
  }
  ll ans=d;
  for(ll i=41;i>=0;i--){
    if(((x>>i)&1)==1)if(ans+((ll)1<<i)<=a[0])ans+=((ll)1<<i);
  }
  cout<<(ans==0?-1:a[0]-ans)<<endl;
}
