#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
long long A[300];
map< pair<pair<long long, long long>, long long>, long long > memo;
long long solve(long long x, long long y, long long tar){
  long long res = 4611686016279904256LL;
  long long tmp;
  pair<pair<long long, long long>, long long> key;
  key = make_pair(make_pair(x, y), tar);
  if(memo.count(key)){
    return memo[key];
  }
  if( (x^y) == tar ){
    res = 0;
  }
  else if(x && (x^y)%2 == tar % 2 ){
    tmp = solve(x/2, y/2, tar/2);
    chmin(res, 2 * tmp);
    tmp = solve((x-1)/2, (y+1)/2, tar/2);
    chmin(res, 2 * tmp + 1);
  }
  return memo[key] = res;
}
int main(){
  int i;
  long long res;
  long long tar = 0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(2);i<(N);i++){
    tar ^= A[i];
  }
  res = solve(A[0], A[1], tar);
  if(res>=A[0]){
    wt_L(-1);
    wt_L('\n');
  }
  else{
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N; ll A[300];
// 
// map< pair<pair<ll, ll>, ll>, ll > memo;
// ll solve(ll x, ll y, ll tar){
//   ll res = ll_inf, tmp;
//   pair<pair<ll, ll>, ll> key;
// 
//   key = make_pair(make_pair(x, y), tar);
//   if(memo.count(key)) return memo[key];
// 
//   if( (x^y) == tar ){
//     res = 0;
//   } else if(x && (x^y)%2 == tar % 2 ){
//     tmp = solve(x/2, y/2, tar/2);
//     res <?= 2 * tmp;
//     tmp = solve((x-1)/2, (y+1)/2, tar/2);
//     res <?= 2 * tmp + 1;
//   }
// 
//   return memo[key] = res;
// }
// 
// {
//   ll res, tar = 0;
//   rd(N,A(N));
//   rep(i,2,N) tar ^= A[i];
//   res = solve(A[0], A[1], tar);
//   wt(if[res>=A[0], -1, res]);
// }


Measured memory_bytes: 3652