#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() 
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) 
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) 
    {
        cin >> B[i];
    }
    vector<int> prefix_xor(N + 1, 0);
    for (int i = 1; i <= N; i++) 
    {
        prefix_xor[i] = prefix_xor[i - 1] ^ A[i - 1];
    }
    int max_value = 0;
    for (int L = 0; L < N; L++) 
    {
        int current_and = B[L];
        for (int R = L; R < N; R++) 
        {
            current_and &= B[R];
            int current_xor = prefix_xor[R + 1] ^ prefix_xor[L];
            max_value = max(max_value, current_xor * current_and);
        }
    }
    cout << max_value << endl;
    return 0;
}