#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;
LL a[N],s;
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i],s^=a[i];
  LL x=a[1],y=a[2];
  s^=a[1]^a[2];
  // (x-ans) ^ (y+ans) =s;
  // dx ^ dy=s 
  // max ->dy
  // (dx+dy-s)=2*(dx&dy)
  LL d=x+y-s;
  if(d&1 || d<0 || d/2>x || (d/2)&s)return cout<<-1,0;
  d>>=1;
  LL ans=d;
  for(int i=45;i>=0;i--){
    if(!(1ll<<i & d)){
        LL nx=ans|1ll<<i;
        if(nx<=a[1]){
            if(s&1ll<<i){
                ans|=1ll<<i;
            }
        }
    }
  }
  if(!ans)cout<<-1<<'\n';
  else cout<<a[1]-ans<<'\n';
  return 0;
}