#include #include using namespace std; using i32 = int; using i64 = long long; using f64 = double; using p2 = pair; using el = tuple; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } void _main() { i64 n; cin >> n; vector a(30, 1); bool ok = true; for (i64 i = 1; i <= n; i++) { i64 b; cin >> b; for (i64 j = 0; j < 30; j++) { i64 x = b >> j & 1, y = i >> j & 1; if (x == 1 && y == 0) ok = false; else if (x == 1 && y == 1) { if (a[j] == 0) ok = false; a[j] = 2; } else if (x == 0 && y == 1) { if (a[j] == 2) ok = false; a[j] = 0; } } } if (!ok) { cout << "-1\n"; return; } i64 ans = 0; for (i64 i = 0; i < 30; i++) { if (a[i] == 2) ans |= 1ll << i; } if (ans == 0) { for (i64 i = 0; i < 30; i++) { if (a[i] == 1) { ans = 1ll << i; break; } } if (ans == 0) { cout << "-1\n"; return; } } cout << ans << "\n"; }