#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int Xor (vector<unsigned>A, int i, int j)
{
    int XOR = A[i]^A[i+1];
    for (i=i+2;i<=j;i++)
        XOR = XOR^A[i];
    return XOR;
}
int And (vector<unsigned>A, int i, int j)
{
    int AND = A[i]&A[i+1];
    for (i=i+2;i<=j;i++)
        AND = AND&A[i];
    return AND;
}
int main()
{
    unsigned N;
    cin >> N;
    vector <unsigned> A (N), B (N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    unsigned maxv = 0;
    for (int i = 0; i < N; i++)
        for (int j = i; j < N; j++)
            if (maxv < Xor(A, i, j)*And(B, i, j)) maxv = Xor(A, i, j)*And(B, i, j);
    cout << maxv << endl;
    return 0;
}