#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

const int N = 310;

int main()
{
	long long a[N];
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) cin >> a[i];
	long long state = 0;
	for (int i = 3; i <= n; i++)
		state ^= a[i];
	// a + b = a ^ b + 2 * (a & b) = state 
	long long p = a[1] + a[2];
	if (p < state) {
		printf("-1\n");
		return 0;
	}

	if ((p - state) & 1) {
		printf("-1\n");
		return 0;
	}

	long long r = (p - state) / 2;
	if (r & state) {
		printf("-1\n");
		return 0;
	}

	long long ans = r;
	for (int i = 50; i >= 0; i--) {
	    long long t = (1LL << i);
		if (!(state & t)) continue;
		if ((ans | t) <= a[1]) ans = ans | t;
	}

	if (ans == 0) printf("-1\n");
	else if (ans > a[1]) printf("-1\n");
	else {
		assert ((ans ^ (p - ans)) == state);
		printf("%lld\n", a[1] - ans);
	}
	return 0;
}
