#include <bits/stdc++.h>
using namespace std;
long long N,A[200022],B[200022],K=1,aaa,s2,bbb,maks,x,a;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> N;
    while(K<N)K<<=1;
    for (int i=1;i<=N;i++){
        cin >> A[i];
        aaa=max(aaa, A[i]);
    }
    for (int i=1;i<=N;i++){
        cin >> B[i];
        bbb=max(bbb,B[i]);
    }
    if (aaa==1){
        cout << bbb << endl;
        return 0;
    }
    else{
        for (int i=1;i<=N;i++){
            for (int j=i;j<=N;j++){
                x=A[i];
                a=B[i];
                for (int k=i+1;k<=j;k++){
                    x=x^A[k];
                    a=a&B[k];
                }
                maks=max(maks,x*a);
            }
        }




    cout << maks << endl;

    }


    return 0;
}