#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 303;

int n;
ll a[N];

bool dp[N][2][2];
ll p[N][2][2];

void solv()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%lld", &a[i]);
    ll x = 0;
    for (int i = 3; i <= n; ++i)
        x ^= a[i];
    dp[0][0][0] = true;
    for (int i = 0; i < 60; ++i)
    {
        for (int z = 0; z < 2; ++z)
        {
            for (int mm = 0; mm < 2; ++mm)
            {
                if (!dp[i][z][mm])
                    continue;
                if (!(x & (1LL << i)))
                {
                    int u = z + 0 + 0;
                    if ((u % 2) == !!((a[1] + a[2]) & (1LL << i)))
                    {
                        if (0 == !!(a[1] & (1LL << i)))
                        {
                            dp[i + 1][u / 2][mm] = true;
                            p[i + 1][u / 2][mm] = max(p[i + 1][u / 2][mm], p[i][z][mm]);
                        }
                        else
                        {
                            dp[i + 1][u / 2][0] = true;
                            p[i + 1][u / 2][0] = max(p[i + 1][u / 2][0], p[i][z][mm]);
                        }
                    }
                    u = z + 1 + 1;
                    if ((u % 2) == !!((a[1] + a[2]) & (1LL << i)))
                    {
                        if (1 == !!(a[1] & (1LL << i)))
                        {
                            dp[i + 1][u / 2][mm] = true;
                            p[i + 1][u / 2][mm] = max(p[i + 1][u / 2][mm], p[i][z][mm] + (1LL << i));
                        }
                        else
                        {
                            dp[i + 1][u / 2][1] = true;
                            p[i + 1][u / 2][1] = max(p[i + 1][u / 2][1], p[i][z][mm] + (1LL << i));
                        }
                    }
                }
                else
                {
                    int u = z + 0 + 1;
                    if ((u % 2) == !!((a[1] + a[2]) & (1LL << i)))
                    {
                        if (0 == !!(a[1] & (1LL << i)))
                        {
                            dp[i + 1][u / 2][mm] = true;
                            p[i + 1][u / 2][mm] = max(p[i + 1][u / 2][mm], p[i][z][mm]);
                        }
                        else
                        {
                            dp[i + 1][u / 2][0] = true;
                            p[i + 1][u / 2][0] = max(p[i + 1][u / 2][0], p[i][z][mm]);
                        }
                    }
                    u = z + 1 + 0;
                    if ((u % 2) == !!((a[1] + a[2]) & (1LL << i)))
                    {
                        if (1 == !!(a[1] & (1LL << i)))
                        {
                            dp[i + 1][u / 2][mm] = true;
                            p[i + 1][u / 2][mm] = max(p[i + 1][u / 2][mm], p[i][z][mm] + (1LL << i));
                        }
                        else
                        {
                            dp[i + 1][u / 2][1] = true;
                            p[i + 1][u / 2][1] = max(p[i + 1][u / 2][1], p[i][z][mm] + (1LL << i));
                        }
                    }
                }
            }
        }
    }
    if (!dp[60][0][0])
    {
        printf("-1\n");
        return;
    }
    if (p[60][0][0] == 0)
    {
        printf("-1\n");
        return;
    }
    printf("%lld\n", a[1] - p[60][0][0]);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 3804