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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll x = 0;
    for (ll i = 2; i < N; i++) x ^= A[i];
    
    ll sum = A[0]+A[1];
    
    ll t = sum-x;
    if (t%2 == 1 || t < 0) {
        cout << -1 << endl;
        return 0;
    }
    
    ll b = t/2;
    if (b > A[0]) {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 50; i >= 0; i--) {
        if ((b>>i)&1) continue;
        if (((x>>i)&1) == 0) continue;
        if (b+(1LL<<i) > A[0]) continue;
        b += (1LL<<i);
    }
    
    if (b == 0 || (b^(sum-b)) != x) {
        cout << -1 << endl;
        return 0;
    }
    cout << A[0]-b << endl;
    return 0;
}
