//#define DEBUG
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
const long long mod = 998244353l;
#define int ll
 
#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) (((a) & (1ll << (p)))>0)
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
 
#define fi first
#define sc second 
#define pb push_back
 
 
#ifdef DEBUG
    #define dbg(s) {s;}
    #define PRELUDE {common();}
#endif
 
#ifndef DEBUG 
    #define PRELUDE { common(); ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define dbg(s)
    #define endl "\n"
#endif
 
#define i32 int32_t
 
#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
 
#define all(v) (v).begin(),(v).end()
 
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ld, ld > point;
 
istringstream _inp;
string _inps;
 
void common() {
    _inp.clear();
    _inps = "";
    _inp.str(_inps);
}
 
int gi() {
    int x;
    while (true) {
        try {
            while (_inp.peek() == ',' || _inp.peek() == ' ') 
                _inp.ignore();
            if (_inp >> x) 
                return x;
            else throw 6;
        } catch (...) {
            getline(cin, _inps);
            _inp.clear();
            _inp.str(_inps);
        }
    }
}
 
// To remove randomization use 0 below:
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int x) { // from [0, n-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}
 
inline ld rf() { // from [0, 1]
    return uniform_real_distribution<ld>(0, 1)(rng);
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
  
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}
 
 
#define X first
#define Y second
 
const int maxn = 1e6 + 7;
const ll inf = 1e9 + 7;
 
const ld eps = 1e-7;
const ld pi = acosl(-1.0);


i32 main() {    
    PRELUDE;        
    
    int n; cin >> n;
    int A, B, C = 0; cin >> A >> B;
    for (int j = 0; j < n - 2; j++) {
        int x; cin >> x; C ^= x;
    }

    int P = B + A;

    // max 1 <= X <= A such that X xor C + X = P 
   
    P -= C;
    if (P % 2 != 0) {
        cout << -1 << endl; return 0;
    }

    P /= 2ll;

    for (int j = 0; j < 60; j++) {
        if (BCHK(P, j) && BCHK(C, j)) {
            cout << -1 << endl; return 0;
        }
    }

    int X = P;
    if (P > A) {
        cout << -1 << endl; return 0;
    }

    for (int j = 60; j >= 0; j--) {
        if (BCHK(C, j)) {
            if (X + (1ll << j) <= A) {
                X += 1ll << j;
            }
        }
    }
    
    if (X == 0) {
        cout << -1 << endl; return 0;
    }
    cout << A - X << endl;
}


Measured memory_bytes: 3620