#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  long long a, b, c = 0;
  cin >> n >> a >> b;
  for (int i = 0; i < n - 2; i++) {
    long long x;
    cin >> x;
    c ^= x;
  }
  long long s = a + b;
  if (s < c || (s - c) & 1) {
    cout << -1 << '\n';
    return 0;
  }
  long long d = (s - c) / 2;
  for (int i = 60; i >= 0; i--) {
    if ((c & (1ll << i)) && ((d | (1ll << i)) <= a)) {
      d |= 1ll << i;
    }
  }
  if ((d ^ (b + a - d) ^ c) || a < d || d <= 0) {
    cout << -1 << '\n';
  } else {
    cout << a - d << '\n';
  }
  return 0;
}
