//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")

#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;
const ll inf=1e18+10;

///---program start---///

const int N=45;

bool dp[N][2][2][3]; /// dp[pref][is_req_a][is_dropped_b][0(<) 1(=) 2(>)]

int get(int k,int a,int b,int c)
{
//    cout<<"get :: "<<k<<" "<<a<<" "<<b<<" "<<c<<"\n";
    memset(dp,0,sizeof(dp));
    dp[0][0][0][1]=1;
    for (int i=0;i<N-1;i++){
        for (int is_req_a=0;is_req_a<2;is_req_a++){
            for (int is_dropped_b=0;is_dropped_b<2;is_dropped_b++){
                for (int ord=0;ord<=2;ord++){
                    if (!dp[i][is_req_a][is_dropped_b][ord]){
                        continue;
                    }
//                    cout<<"reacheable :: "<<i<<" "<<is_req_a<<" "<<is_dropped_b<<" "<<ord<<"\n";
                    for (int cur_to_set_to_i=0;cur_to_set_to_i<2;cur_to_set_to_i++){
                        int cur_a_value=(a>>i)&1;
                        int cur_b_value=(b>>i)&1;
                        int cur_c_value=(c>>i)&1;
                        int cur_k_value=(k>>i)&1;

                        int to___is_req_a=0;
                        int to___is_dropped_b=0;
                        int to___ord=0;

                        /// a process
                        if (is_req_a){
                            if (cur_a_value){
                                cur_a_value=0;
                            }
                            else{
                                to___is_req_a=1;
                                cur_a_value=1;
                            }
                        }
                        if (cur_a_value==cur_to_set_to_i){
                            cur_a_value=0;
                        }
                        else if (cur_a_value==1 && cur_to_set_to_i==0){

                        }
                        else if (cur_a_value==0 && cur_to_set_to_i==1){
                            to___is_req_a=1;
                            cur_a_value=1;
                        }
                        else{
                            assert(0);
                        }

                        //// b process
                        if (is_dropped_b){
                            if (cur_b_value==0){
                                cur_b_value=1;
                            }
                            else{
                                to___is_dropped_b=1;
                                cur_b_value=0;
                            }
                        }
                        if (cur_to_set_to_i==0){

                        }
                        else if (cur_b_value==0 && cur_to_set_to_i==1){
                            cur_b_value=1;
                        }
                        else if (cur_b_value==0 && cur_to_set_to_i==1){
                            cur_b_value=1;
                        }
                        else if (cur_b_value==1 && cur_to_set_to_i==1){
                            to___is_dropped_b=1;
                            cur_b_value=0;
                        }
                        else{
                            assert(0);
                        }

                        /// ord process
                        if (cur_to_set_to_i!=cur_k_value){
                            if (cur_to_set_to_i<cur_k_value){
                                to___ord=0;
                            }
                            else{
                                to___ord=2;
                            }
                        }
                        else{
                            to___ord=ord;
                        }

                        if (cur_a_value^cur_b_value^cur_c_value){
                            continue;
                        }

//                        cout<<"    "<<"by setting "<<cur_to_set_to_i<<"\n";
//                        cout<<"    go :: "<<i+1<<" "<<to___is_req_a<<" "<<to___is_dropped_b<<" "<<to___ord<<"\n";

                        dp[i+1][to___is_req_a][to___is_dropped_b][to___ord]=1;
                    }
                }
            }
        }
    }
//    cout<<"res :: "<<(dp[N-1][0][0][0] || dp[N-1][0][0][1])<<"\n";
    return dp[N-1][0][0][0] || dp[N-1][0][0][1];
}

int get_ans(int a,int b,int c)
{
    if (!get(a-1,a,b,c)){
        return -1;
    }
    int l=0,r=a-1;
    while (r-l>0){
        int m=(l+r)/2;
        if (get(m,a,b,c)){
            r=m;
        }
        else{
            l=m+1;
        }
    }
    assert(((a-l)^(b+l)^c)==0);
    return l;
}

int A[arr];

signed main()
{
    #ifdef __APPLE__
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int n;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>A[i];
    }
    int a=0;
    int b=0;
    int c=0;

    a=A[0];
    b=A[1];
    for (int i=2;i<n;i++){
        c^=A[i];
    }

    cout<<get_ans(a,b,c)<<"\n";
}


Measured memory_bytes: 3580