#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

int N;
long long int A[333];
long long int Z, X, Y, S;
int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) { cin >> A[i]; }

	S = A[1] + A[2];

	for (int i = 3; i <= N; i++) {
		Z ^= A[i];
	}

	if (S < Z) { cout << -1 << endl; return 0; }
	long long int tmp = S - Z;

	tmp = tmp / 2;

	long long int tot = S - tmp * 2;

	X = tmp; Y = tmp;

	/*cout << "S=   " << bitset<64>(S) << endl;
	cout << "Z=   " << bitset<64>(Z) << endl;
	cout << "X&Y= " << bitset<64>(tmp) << endl;
	*/
	for (int i = 60; i >= 0; i--) {
		long long int val = 1LL << i;
		if (tot >= val) {
			tot -= val;
			if (X + val <= A[1]) { X += val; }
			else { Y += val; }
		}
		
	}

	/*cout << "X=   " << bitset<64>(X) << endl;
	cout << "Y=   " << bitset<64>(Y) << endl;
	cout << "A[1]=" << bitset<64>(A[1]) << endl;
	*/
	if (X + Y == S && (X^Y) == Z && ((X&Y)==tmp) && A[1]>=X && X>0) { cout << (A[1] - X)<< endl; }
	else { cout << -1 << endl; }

	return 0;
}