#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll x, y, o, a = 0, b = 0;
    cin >> n >> x >> y;
    a = x + y;
    for (int i = 3; i <= n; i++) cin >> o, b ^= o;
    if (a % 2 != b % 2) cout << -1;
    else {
        ll c = (a - b) / 2, z = 0;
        for (int i = 42; i >= 0; i--) {
            if (c & (1ll << i)) z += (1ll << i);
        }
        for (int i = 42; i >= 0; i--) {
            if (b & (1ll << i)) {
                if (z + (1ll << i) <= x) z += (1ll << i);
            }
        }
        if (z == 0 || ((z ^ (a - z)) != b) || z > x) cout << -1;
        else cout << x - z;
    }
}
