#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

using namespace std;

using i64 = long long;


int trie[200069][31];

int nenad_stanojevic = 2;

void ins(int x){
    int node = 1;

    for(int i = 30;i >= 0;i--){
        if(x & (1LL << i)){
            if(trie[node][i] == 0){
                trie[node][i] = nenad_stanojevic++;
            }
            node =  trie[node][i];
        }
    }
}

int ask(int x){

    int sum = 0;

    int node = 1;

    for(int i = 30;i >= 0;i--){
        if(!(x & (1LL << i))){
            if(trie[node][i] != 0){
                sum += (1LL << i);

                node = trie[node][i];
            }
        }
    }

    return x + sum;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> a(n);
    bool a1 = true;
    bool b1 = true;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        if(a[i] != 1){
            a1 = false;
        }
    }

    vector<int> b(n);

    for(int i = 0;i < n;i++){
        cin >> b[i];
        if(b[i] != 1){
            b1 = false;
        }
    }

    if(a1){
        cout << *max_element(all(b)) << "\n";
    }else if(b1){
        int xorovic = 0;
        int res = 0;
        for(int i = 0;i < n;i++){
            xorovic ^= a[i];

            ins(xorovic);

            res = max(res, ask(xorovic));
        }

        cout << res << "\n";
    }else{
        i64 res = 0;
        for(int i = 0;i < n;i++){
            i64 res1 = a[i];
            i64 res2 = b[i];
            res = max(res, res1 * res2);
            for(int j = i + 1;j < n;j++){
                res1 |= a[j];
                res2 &= b[j];

                res = max(res, res1 * res2);
            }
        }

        cout << res << "\n";
    }


}