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

long n;
long a, b, c;
long sub() {
  long x = a + b;
  if (x < c) return -1;
  if (x % 2 != c % 2) return -1;
  long cap = (x - c) / 2;
  if (cap & c) return -1;
  long rem = a - cap;
  if (rem < 0) return -1;
  long ans = cap;
  for (int k = 50; k >= 0; --k) {
    if ((1ll << k) > rem) continue;
    if (c & (1ll << k)) {
      ans += 1ll << k;
      rem -= 1ll << k;
    }
  }
  cerr << ans << endl;
  return ans;
}

int main() {
  cin >> n;
  cin >> a >> b;
  for (int i = 2; i < n; ++i) {
    long p;
    cin >> p;
    c ^= p;
  }
  
  long ans = sub();
  if (ans <= 0) {
    cout << -1 << endl;
  } else {
    cout << a - ans << endl;
  }
}