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

int NG() {
    cout << -1 << "\n";
    return 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<long long> A(N);
    long long XOR = 0;
    for (auto &x: A) {
        cin >> x; XOR ^= x;
    }
    long long X = A[0], Y = A[1];
    XOR ^= X ^ Y;
    long long AND = X + Y - XOR;
    if (AND % 2) return NG();
    else AND /= 2;
    if ((AND & XOR) || (AND > X)) return NG();
    long long Ans = AND;
    for (int i = 40; i >= 0; i--) {
        if (XOR & (1LL << i)) {
            if (Ans + (1LL << i) <= X) {
                Ans += 1LL << i;
            }
        }
    }
    if (Ans == 0) return NG();
    cout << X - Ans << "\n";
    return 0;
}