#include <bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define yes "YES"
#define no "NO "

using namespace std;

using ll = long long;
const ll inf=1e18;
using ld = long double;
using pll = pair<ll,ll>;

vector<ll>a,b;
ll n;
void solve()
{
    ll i,bt,at,j,res=0;
    for(i=0;i<n;i++)
    {
        bt=b[i];
        at=0;
        for(j=i;j<n;j++)
        {
            bt&=b[j];
            at^=a[j];
            res=max(res,bt*at);
        }
    }
    cout << res << endl;


}

ll reshi(vector<ll> niz,ll n)
{

    ll mx=0,tren=0;
    set<ll>s;
    for(ll i=32;i>=0;i--)
    {
        tren|=(1ll<<i);
        for(ll i=0;i<n;i++)
        {
            s.insert(niz[i]&tren);
        }
        ll nv=mx|(1ll<<i);
        for(auto &x:s)
        {
            if(s.count(nv^x))
            {
                mx=nv;
                break;
            }
        }
        s.clear();
    }
    return mx;


}



void drugisolve()
{

    vector<ll>pref(n+1);
    pref[0]=0;
    for(ll i=1;i<=n;i++)
    {
        pref[i]=a[i-1]^pref[i-1];
    }
    cout << reshi(pref,n+1);
}

/*
5
7 5 6 1 2
1 3 2 0 1

*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    a.resize(n);
    b.resize(n);
    bool sveJedan=true,pliz=true;
    ll mx=0;
    for(auto &x:a)
    {
        cin >> x;
        if(x!=1)
        {
            sveJedan=false;
        }
    }
    for(auto &x:b)
    {
        cin >> x;
        mx=max(mx,x);
        if(x!=1)
        {
            pliz=false;
        }
    }
    if(sveJedan)
    {
        cout << mx;
        return 0;
    }
    if(pliz)
    {
        drugisolve();
        return 0;
    }
    solve();

}