#include<iostream>
#include<iomanip>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int msb_(int x) { return 31 - __builtin_clz(x); }
int64_t msb(int64_t x) {
  int64_t y = x>>32;
  if(y == 0) return msb_((int)x);
  return msb_((int)y) + 32;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  int64_t a1, a2; std::cin >> a1 >> a2;
  int64_t sum = 0;
  for(int i = 2; i < N; ++i) {
    int64_t a; std::cin >> a; sum ^= a;
  }
  int64_t tmp = a1^a2^sum;
  if(tmp == 0) fin(0);
  if(tmp&1) fin(-1);
  int64_t an = a1+a2 - sum;
  if(an < 0) fin(-1);
  an /= 2;
  if(an&sum) fin(-1);
  if(an > a1) fin(-1);
  int64_t dif = a1-an;
  int64_t mask = ((int64_t)1<<msb(dif)+1)-1;
  sum &= mask;
  while(sum > dif) {
    int64_t ms = (int64_t)1<<msb(dif);
    dif -= ms;
    sum -= ms;
    int64_t mask = ((int64_t)1<<msb(dif)+1)-1;
    sum &= mask;
  }
  dif -= sum;
  if(dif == a1) fin(-1);
  fin(dif);
  return 0;
}
