#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

int XORf(vector<ll> &A, ll i, ll j) {
    ll r = 0;
    for (int k = i; k <= j; ++k) {
        r ^= A[k]; 
    }
    return r;
}

int ANDf(vector<ll>& B, ll i, ll j) {
    ll r = B[i];
    for (int k = i + 1; k <= j; ++k) {
        r &= B[k];
    }
    return r;
}

int max(vector<ll>& A, vector<ll>& B, ll N) {
    ll maxR = 0;
    
    for (int i = 0; i < N; ++i) {
        for (int j = i; j < N; ++j) {
            ll XOR = XORf(A, i, j);
            ll AND = ANDf(B, i, j);
            ll konacan = XOR * AND;
            maxR = max(maxR, konacan);
        }
    }

    return maxR;
}

void unos1(ll N,vector<ll> &A)
{
	for(int i=0;i<N;i++)
	{
		cin >> A[i];
	}
}
void unos2(ll N,vector<ll> &B)
{
	for(int i=0;i<N;i++)
	{
		cin >> B[i];
	}
}

int main() {
    
    
    ll N; 
    
    cin >> N;
    
	vector <ll> A(N);
	vector <ll> B(N);
	
	unos1(N,A);
	unos2(N,B);
    
    ll r = max(A, B, N);

    cout << r ;

    return 0;
}