#include [[nodiscard]] static inline constexpr int_fast32_t solve(const uint_fast32_t n, const std::vector& b) noexcept { uint_fast32_t ans = 0; for (uint_fast32_t i = 1; i <= n; ++i) for (uint_fast32_t j = 0; j != 18; ++j) if ((b[i] >> j) & 1) { if (!((i >> j) & 1)) [[unlikely]] return -1; else ans |= UINT32_C(1) << j; } if (ans == 0) for (ans = 1; ans <= n; ans <<= 1); return ans; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); uint_fast32_t n, i; std::cin >> n; std::vector b(n + 1); for (i = 1; i <= n; ++i) std::cin >> b[i]; std::cout << solve(n, b) << '\n'; return 0; }