#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ void Solve() { int n; IN(n); vector a(n); IN(a); array s; s.fill(-1); for (int i : Rep(0, n)) { int i1 = i + 1; int ai = a[i]; for (int k : Rep(0, 20)) { int aik = ai >> k & 1; int i1k = i1 >> k & 1; if (aik && i1k) { if (s[k] == 0) { OUT(-1); return; } s[k] = 1; } else if (aik) { OUT(-1); return; } else if (i1k) { if (s[k] == 1) { OUT(-1); return; } s[k] = 0; } else { } } } int ans = 0; for (int k : Rep(0, 20)) { if (s[k] == 1) { ans |= 1 << k; } } OUT(ans); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Solve(); } #elif __INCLUDE_LEVEL__ == 1 #include template concept MyRange = std::ranges::range && !std::convertible_to; template concept MyTuple = std::__is_tuple_like::value && !MyRange; namespace std { istream& operator>>(istream& is, MyRange auto&& r) { for (auto&& e : r) is >> e; return is; } istream& operator>>(istream& is, MyTuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, MyRange auto&& r) { auto sep = ""; for (auto&& e : r) os << exchange(sep, " ") << e; return os; } ostream& operator<<(ostream& os, MyTuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std using namespace std; #define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__) #define IN(...) (cin >> forward_as_tuple(__VA_ARGS__)) #define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n') #endif // __INCLUDE_LEVEL__ == 1