#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;

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;


}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    a.resize(n);
    b.resize(n);
    bool sveJedan=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(sveJedan)
    {
        cout << mx;
        return 0;
    }
    solve();

}