using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.La;
		long d=0;
		for(int i = 0;i<n;i++) {
			if(i>1){d^=a[i];}
		}
		var b0=a[0];
		var b1=a[1];
		long ans=0;
		if(d==0){
			if((a[0]-a[1])%2==0&&a[0]>=a[1]){
				ans=(a[0]-a[1])/2;
				if(a[0]-ans>0){
					Console.WriteLine(ans);
					return;
				}
			}
			Console.WriteLine(-1);
			return;
		}
		while(true){
			int mm=Max(Bsr(d),Max(Bsr(b0),Bsr(b1)))+1;
			if(b0<=0){
				Console.WriteLine(-1);
				return;
			}
			if((b0^b1^d)==0){
				Console.WriteLine(ans);
				return;
			}
			for(int i = 0;i<mm;i++) {
				long z=1L<<(mm-i-1);
				if(((b0^b1)&z)!=(d&z)){
					var x=Min((b0&(z-1))+1,z-((z-1)&b1));
					b0-=x;
					b1+=x;
					ans+=x;
					break;
				}
			}
		}
	}
	static int Bsr(long b){
		int n=0;
		if(b==0){return -1;}
		if((b&-4294967296)!=0){b=b&-4294967296;n+=32;}
		if((b&-281470681808896)!=0){b=b&-281470681808896;n+=16;}
		if((b&-71777214294589696)!=0){b=b&-71777214294589696;n+=8;}
		if((b&-1085102592571150096)!=0){b=b&-1085102592571150096;n+=4;}
		if((b&-3689348814741910324)!=0){b=b&-3689348814741910324;n+=2;}
		if((b&-6148914691236517206)!=0){b=b&-6148914691236517206;n+=1;}
		return n;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27868