// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!!
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - negative arithmetic, ceiling division, modulo (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)
// - forgetting to rename recursive call when copy/pasting recursive function (WA)
// - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)

#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (4e18) + 9;
const int MOD = (1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { r, d, l, u };
int dx[] = { 0, 1, 0,-1 };
int dy[] = { 1, 0,-1, 0 };

//enum diR { d, r, u, l , dr, ur, dl, ul };
int dX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dY[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou"; //and sometimes "aeiouy"

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D matrix to 1D array. (Zero-indexed)
int ord(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D matrix . (One-indexed)
ii rord(int n, int nCol) {
	int r = n%nCol, c = n / nCol;
	if (n%nCol == 0) c--, r = nCol;
	return ii(r, c);
}


ll power(ll base, ll exp) { 
ll ans = 1; 
base %= MOD; 
while (exp > 0) { 
if (exp & 1) ans = (ans * base) % MOD; 
exp >>= 1; 
base = (base * base) % MOD; 
} 
return ans;
} 

ll modInverse(ll a) {
 return power(a, MOD - 2);
} 

const int NN = 2000010;
ll fact[NN]; 

void init() { 
fact[0] = 1; 
for (int i = 1; i < NN; ++i) fact[i] = (fact[i - 1] * 1LL * i) % MOD;
} 

int nCr(int n, int r) { 
return (fact[n] * modInverse(fact[r] * 1LL * fact[n - r])) % MOD;
}

int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);

int n;
cin>>n;
ll a1, a2, x, xr=0;
cin>>a1>>a2;
lop(i, n-2) cin>>x, xr ^= x;
if((a1+a2-xr)%2 or a1+a2 < xr) return cout << -1 << endl, 0;
ll a = -OO, b = 0, sum = a1+a2;
for(ll bit = 40; bit >= 0; bit--){
// 0 1 or 1 0
if(xr & (1ll<<bit)){
a += (1ll<<bit);
if(a1&(1ll<<bit)) a = max(a, b), b += (1ll<<bit);
sum -= 1ll<<bit;
}
else{
if(sum >= (1ll<<(bit+1))){
if(not (a1 & (1ll<<bit))) b = -OO;
a += 1ll<<bit;
b += 1ll<<bit;
sum -= 1ll<<(bit+1);
} 
else{
if(a1 & (1ll<<bit)) a = max(a, b);
} 
}
} 
a = max(a, b);
if(not sum and a > 0) cout<<a1 - a<<endl;
else cout<<-1<<endl;

	return 0;
}


Measured memory_bytes: 3668