#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, v, ans = 0; cin >> n; for(int i = 1; i <= n; i++){ cin >> v; if ((v & i) != v){ cout << "-1\n"; return 0; } ans |= (v & i); } cout << ans << '\n'; }