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

using namespace std;

long long a[300];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long x = 0;
	for (int i = 2; i < n; i++)
		x ^= a[i];
	long long t = a[0] + a[1] - x;
	if (t & 1) {
		puts("-1");
		return 0;
	}
	t /= 2;
	if (t > a[0]) {
		puts("-1");
		return 0;
	}
	for (int i = 39; i >= 0; i--) {
		if (x & (1LL << i)) {
			if (t & (1LL << i)) {
				puts("-1");
				return 0;
			}
			if (t + (1LL << i) <= a[0]) {
				t += (1LL << i);
			}
		}
	}
	if (t == 0) {
		puts("-1");
		return 0;
	}
	printf("%lld\n", a[0] - t);
	return 0;
}
