import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; } 
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){
  int n = uniform(2, 100);
  print(n);
  long[] as;
  foreach(i; 0 .. n) as ~= uniform(1, 1000); 
  print(as.unsplit);
}
void jury(){
  int n = scan!int;
  long[] as = scan!long(n);

  long ans = -1;
  foreach(x; 0 .. as[0]){
    long tmp = (as[0] - x) ^ (as[1] + x);
    if(as.length > 2) foreach(a; as[2 .. $]) tmp ^= a;
    if(tmp == 0){
      ans = x;
      break;
    }
  }
  ans.writeln;
}
void solve(){
  int n = scan!int;
  long[] as = scan!long(n);
  as ~= 0;
  log("as:", as);
  
  long u, v;
  u = as[0] + as[1];
  foreach(a; as[2 .. $]) v ^= a;
  log("u:", u, "v:", v);
  
  long d = u - v;
  log("d:", d);

  if(d  < 0){
    "-1".writeln;
    return;
  }
  if(d % 2 == 1){
    "-1".writeln;
    return;
  }

  d /= 2;
  if(d > as[0]){
    "-1".writeln;
    return;
  }
  if(d & v){
    "-1".writeln;
    return;
  }

  long m = 1;
  while(m * 2 <= as[0]) m *= 2;
  log("m:", m);

  while(m > 0){
  	if((m & v) && d + m <= as[0]) d += m;
    m /= 2;
  }
  if(d == 0){
    "-1".writeln;
    return;
  }
  log("d:", d);
  
  long ans = as[0] - d;
  ans.writeln;
}
/*
　u := a[0] + a[1]
　v := a[2] ^ a[3] ^ ... ^ a[n-1]
とするとき、題意は
　a + b = u
　a ^ b = v
をみたす、a[0] 以下で最大の a を探すことである

u = 10011
v =  1011
であるとき その差は 1000 つまり 200
つまり v は 剰余をとる前は 1211 だったみたいな感じ
これをaとbに分ける
よって 100 は必須で、それ以外のビットは
a[0]に届かない限りなるべく立てる
*/
