#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define LL long long

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x = 0) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}
template<class TypeName>
vector<TypeName> getVector1D(int n, TypeName val) {
    return vector<TypeName>(n, val);
}
template<class TypeName>
vector<vector<TypeName> > getVector2D(int n1, int n2, TypeName val) {
    vector<vector<TypeName> > res(n1);
    for (int i = 0; i < n1; ++i) {
        res[i] = vector<TypeName>(n2, val);
    }
    return res;
}
template<class TypeName>
vector<vector<vector<TypeName> > > getVector3D(int n1, int n2, int n3, TypeName val) {
    vector<vector<vector<TypeName> > > res(n1);
    for (int i = 0; i < n1; ++i) {
        res[i] = vector<vector<TypeName> >(n2);
        for (int j = 0; j < n2; ++j) {
            res[i][j] = vector<TypeName>(n3, val);
        }
    }
    return res;
}
template<class TypeName>
vector<vector<vector<vector<TypeName> > > > getVector4D(int n1, int n2, int n3, int n4, TypeName val) {
    vector<vector<vector<vector<TypeName> > > > res(n1);
    for (int i = 0; i < n1; ++i) {
        res[i] = vector<vector<vector<TypeName> > >(n2);
        for (int j = 0; j < n2; ++j) {
            res[i][j] = vector<vector<TypeName> >(n3);
            for (int k = 0; k < n3; ++k) {
                res[i][j][k] = vector<TypeName>(n4, val);
            }
        }
    }
    return res;
}

LL Mint::md = 1000000007;

LL n;
vector<LL> a;

vector<LL> toBit(LL x) {
	vector<LL> res(0);
	while (x) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}
LL toNum(vector<LL> &x) {
	LL res = 0;
	LL base = 1;
	for (int i = 0; i < x.size(); ++i) {
		res += (x[i] * base);
		base *= 2;
	}
	return res;
}

void solve(LL s, LL x, LL &low, LL &high, LL a0) {
	LL dd = s - x;
	if (dd < 0) {
		low = high = -1;
		return ;
	}
	auto db = toBit(dd), xb = toBit(x), sb = toBit(s);
	int nn = sb.size();
	while (db.size() < nn) {
		db.push_back(0);
	}
	while (xb.size() < nn) {
		xb.push_back(0);
	}
	if (sb[nn - 1] && !xb[nn - 1]) {
		db[nn - 1] = 1;
	}
	// cout << "db: ";
	// for (int i = 0; i < nn; ++i) {
	// 	cout << db[i];
	// }
	// cout << endl;
	// cout << "xb: ";
	// for (int i = 0; i < nn; ++i) {
	// 	cout << xb[i];
	// }
	// cout << endl;
	// cout << "sb: ";
	// for (int i = 0; i < nn; ++i) {
	// 	cout << sb[i];
	// }
	// cout << endl;
	vector<LL> lb(0), hb(0);
	vector<LL> und(0);
	LL thres = -1;
	for (LL i = 0; i < nn; ++i) {
		// cout << "i = " << i << endl;
		// cout << xb[i] << endl;

		if (xb[i] == 0) {
			// if (sb[i] != db[i]) {
			// 	low = high = -1;
			// 	return ; 
			// }
			if (i + 1 < nn && db[i + 1]) {
				lb.push_back(1);
				hb.push_back(1);
			} else {
				lb.push_back(0);
				hb.push_back(0);
			}
		} else {
			// if (sb[i] == db[i]) {
			// 	low = high = -1;
			// 	return ;
			// }
			// if (!db[i] && (i + 1 < nn && db[i + 1])) {
			// 	low = high = -1;
			// 	return ;
			// }
			lb.push_back(0);
			hb.push_back(0);
			und.push_back(i);
		}
	}
	// cout << low << ' ' << high << endl;
	low = toNum(lb); high = toNum(hb);
	if (low >= a0) {
		low = high = -1;
		return ;
	}
	if (und.size() > 0) {
		for (LL i = und.size() - 1; i >= 0; --i) {
			LL ddd = (LL)(1) << und[i];
			if (low + ddd >= a0) {
				hb[und[i]] = 1;
				high += ddd;
			} else {
				lb[und[i]] = 1;
				low += ddd;
			}
		}
	}
	if (low == 0) {
		low = high = -1;
		return ;
	}
	// cout << low << ' ' << high << endl;
	// high = toNum(hb);
	// cout << low << ' ' << high << endl;

	// if (und.size() > 0) {
	// 	for (int i = 0; i < und.size(); ++i) {
	// 		cout << und[i] << ' ';
	// 	}
	// 	cout << endl;
	// 	for (int i = und.size() - 1; i >= 0; --i) {
	// 		if (i + 1 == und.size()) {
	// 			hb[und[i]] = 1;
	// 		} else {
	// 			lb[und[i]] = 1;
	// 		}
	// 	}
	// }
	// low = toNum(lb); high = toNum(hb);
	// cout << "s = " << s << ", x = " << x << endl;
	// cout << low << ' ' << high << endl;
	// cout << (low ^ high) << ' ' << (low + high) << endl;
	if (((low ^ high) != x) || (low + high != s)) {
		low = high = -1;
		return ;
	}
}

int main() {
	cin >> n;
	a = vector<LL>(n, 0);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	LL xx = 0;
	for (int i = 0; i < n; ++i) {
		xx = xx ^ a[i];
	}
	if (xx == 0) {
		cout << 0 << endl;
		return 0;
	}
	xx = xx ^ a[0];
	xx = xx ^ a[1];
	LL low, high;
	solve(a[0] + a[1], xx, low, high, a[0]);
	if (low == -1) {
		cout << "-1" << endl;
		return 0;
	} else {
		cout << (a[0] - low) << endl;
	}
	return 0;
	// LL l = 0, r = a[0] - 1;
	// LL mid = (l + r) / 2;
	// while (l < r) {
	// 	if (((a[0] - mid) ^ (a[1] + mid)) == xx) {
	// 		r = mid;
	// 	} else {
	// 		l = mid + 1;
	// 	}
	// 	mid = (l + r) / 2;
	// 	cout << "l = " << l << ", r = " << r << endl;
	// }
	// if (((a[0] - l) ^ (a[1] + l)) == xx) {
	// 	cout << l << endl;
	// } else {
	// 	cout << (-1) << endl;
	// }
	// vector<LL> b0 = toBit(a[0]), b1 = toBit(a[1]), rs = toBit(xx);
	// LL l0 = b0.size(), l1 = b1.size(), lr = rs.size();
	// for (LL i = 0; i < l0; ++i) {
	// 	cout << b0[i];
	// }
	// cout << endl;
	// for (LL i = 0; i < l1; ++i) {
	// 	cout << b1[i];
	// }
	// cout << endl;
	// for (LL i = 0; i < lr; ++i) {
	// 	cout << rs[i];
	// }
	// cout << endl;
	// LL ml = max(l0, max(l1, lr)) + 1;
	// while (b0.size() < ml) {
	// 	b0.push_back(0);
	// }
	// while (b1.size() < ml) {
	// 	b1.push_back(0);
	// }
	// while (rs.size() < ml) {
	// 	rs.push_back(0);
	// }
	// LL nn = 60;
	// LL inf = a[0] + 1;
	// // vector<LL> f(nn, -1), g(nn, -1);
	// auto f = getVector3D(nn, 3, 3, (LL)(inf));
	// auto g = getVector3D(nn, 3, 3, (LL)(-1));
	// // f[i]: minimum number to have lowest i bits compatible, where 0 gives some to 1, and state (b, c) for 0, 1(0: +1, 1: 0, 2: -1)
	// // g[i]: maximum number, 1 to 0, state (b, c)
	// for (LL i = 0; i < ml; ++i) {

	// 	// f[i][0][...] = inf(cannot do it)
	// 	// f[i][...][2] = inf(cannot do it)
	// 	// g[i][...][0] = -1(cannot do it)
	// 	// g[i][2][...] = -1

	// 	// so what we can do is: 
	// 	// f[i][1][0, 1], f[i][2][0, 1]
	// 	// g[i][0][1, 2], g[i][1][1, 2]

	// 	if (i == 0) {
	// 		if ((b0[i] ^ b1[i]) != rs[i]) {
	// 			cout << "-1" << endl;
	// 			return 0;
	// 		}
	// 		if (b0[i] == 0 && b1[i] == 0) {
	// 			f[0][1][1] = 0;
	// 			f[0][2][1] = 1;

	// 			g[0][1][1] = 0;
	// 			g[0][1][2] = 1;
	// 		} else if (b0[i] == 0 && b1[i] == 1) {
	// 			f[0][1][1] = 0;
	// 			f[0][2][0] = 1;

	// 			g[0][1][1] = 1;
	// 		} else if (b0[i] == 1 && b1[i] == 0) {
	// 			f[0][1][1] = 0;

	// 			g[0][1][1] = 0;
	// 			g[0][0][2] = 1;
	// 		} else {
	// 			f[0][1][1] = 0;
	// 			f[0][2][0] = 1;

	// 			g[0][1][1] = 0;
	// 			g[0][0][2] = 1;
	// 		}
	// 		continue;
	// 	}

	// 	// else, we want to update f[i][1][0, 1], f[i][2][0, 1]
	// 	// and g[i][0][1, 2], g[i][1][1, 2]
		
	// 	// or, update from f[i - 1][1][0, 1], f[i - 1][2][0, 1]
		
	// 	// from f[i - 1][2][1]
	// 	if (b0[i] == 0) {
	// 		if ((b0[i] ^ b1[i]) != rs[i]) {
	// 			f[i][2][1] = min(f[i - 1][2][1], f[i][2][1]);
	// 		}
	// 	} else {
	// 		if ((b0[i] ^ b1[i]) != rs[i]) {
	// 			f[i][1][1] = min(f[i - 1][2][1], f[i][1][1]);
	// 		}
	// 	}

	// 	// from f[i - 1][2][0]
	// 	if (b0[i] == 0) {
	// 		if ((b0[i] ^ b1[i]) == rs[i]) {
				
	// 		}
	// 	}



	// 	// if ((b0[i] ^ b1[i]) == rs[i]) {

	// 	// }
	// }
	// return 0;
}

Measured memory_bytes: 3644