#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 5e5 + 10;
int N;
LL A[500], S, X, D, ANS;
int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
    {
        scanf("%lld", &A[i]);
        if (i <= 2)
            S += A[i];
        else
            X ^= A[i];
    }
    if (S - X < 0 || (S - X) % 2 != 0)
    {
        printf("-1\n");
        return 0;
    }
    else
        D = (S - X) / 2;
    LL ANS = D;
    for (int i = 60; i >= 0; i--)
    {
        int x = ((X >> i) & 1LL), d = ((D >> i) & 1LL);
        if (d && x)
        {
            printf("-1\n");
            return 0;
        }
        if (!d && x && (ANS | (1LL << i)) <= A[1])
            ANS |= (1LL << i);
    }
    if (ANS == 0 || ANS > A[1])
        printf("-1\n");
    else
        printf("%lld\n", A[1] - ANS);
    return 0;
}