#include <iostream>
#include <cmath>
using namespace std;
int binarni (int x, int b1,int b2)
{
    int y=0,k=0;
    while(x>0)
    {
        y=y+pow(b1,k)*(x%b2);
        k++;
        x/=b2;
    }
    return y;
}
int konjunkcija (int x, int y)
{
    int k=0;
    x=binarni(x,10,2);
    //y=binarni(y,10,2);
    while(x>0&&y>0)
    {
        if(x%10==1&&y%10==1)
            k=10*k+1;
        else
            k=10*k;
        x/=10;
        y/=10;
    }
    return k;
}
int disjunkcija(int x, int y)
{
    int k=0;
    x=binarni(x,10,2);
    //y=binarni(y,10,2);
    while(x>0||y>0)
    {
        if(x%10==1||y%10==1)
            k=10*k+1;
        else
            k=10*k;
        x/=10;
        y/=10;
    }
    return k;
}
int maks (int a[], int b[],int l, int r)
{
    int s1=0, s2=0;
    s1=binarni(b[l],10,2);
    s2=binarni(a[l],10,2);
    for (int i = l+1; i <= r; i++)
    {
        s1=konjunkcija(b[i],s1);
        s2=disjunkcija(a[i],s2);
    }
    return binarni(s1,2,10)*binarni(s2,2,10);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    int maksi=0;
    for (int i = 0; i < n; i++)
        for (int j = i+1; j < n; j++)
            maksi=max(maksi,maks(a,b,i,j));
    cout << maksi << endl;
    return 0;
}