#include<bits/stdc++.h>
using namespace std;

const int N = 305;
typedef long long LL;

int n;
LL a[N], x, k;

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	for(int i = 3; i <= n; i++)
		x = x^a[i];
	k = a[1] + a[2] - x;
	if(k%2 == 1 || k < 0) {
		cout<<-1<<endl;
		return 0;
	}
	k /= 2;
	if(k > a[1]) {
		cout<<-1<<endl;
		return 0;
	}
	for(int i = 50; i >= 0; i--) 
		if(x&(1ll<<i) && k + (1ll<<i) <= a[1]) k += 1ll<<i;
	if(a[1] - k < 0 || a[1] - k > a[1] - 1|| (k^(a[1] + a[2] - k)) != x) {
		cout<<-1<<endl;
		return 0;
	}
	cout<<a[1] - k<<endl; 
	return 0;
}