#include <iostream>
#include <cassert>

void ng (long long val = -1LL) {
    std::cout << val << '\n';
    exit(0);
}

int main() {
    int n;
    long long a, b, x = 0;
    std::cin >> n >> a >> b;
    for (int i = 2; i < n; i++) {
        long long e;
        std::cin >> e;
        x ^= e;
    }

    long long d = (a + b) - x;
    if (d < 0 or d % 2 == 1) ng();
    d >>= 1;
    for (int i = 0; i < 50; i++) {
        if ((x >> i & 1) and (d >> i & 1)) ng();
    }

    long long ans = 0;
    for (int i = 50; i --> 0;) {
        int bd = (d >> i & 1), bx = (x >> i & 1);
        if (bd == 1 and bx == 0) {
            ans += (1LL << i);
        }
    }
    for (int i = 50; i --> 0;) {
        int bd = (d >> i & 1), bx = (x >> i & 1);
        if (bd == 0 and bx == 1) {
            if (ans + (1LL << i) < a) ans += (1LL << i);
        }
    }

    if (ans == 0 or ans > a) ans = -1;
    else ans = (a - ans);
    std::cout << ans << '\n';
    return 0;
}
