#include <iostream>
#include <set>

using namespace std;

unsigned a[200000],b[200000],axor[200001];

unsigned int Xor(int l,int r){
return axor[r+1]^axor[l];
}

unsigned int And(int l,int r){
unsigned int R;
R=b[l];
for(int i=l+1;i<=r;i++){
    R=R&b[i];
    if (R==0) return 0;
}
return R;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
set<unsigned long long,greater<int>> res;
int n;
cin >> n;
axor[0]=0;
for(int i=0;i<n;i++){
     cin >> a[i];
     axor[i+1]=axor[i]^a[i];
}
for(int i=0;i<n;i++){
    cin >> b[i];
    for(int j=0;j<=i;j++){
        res.insert(Xor(j,i)*And(j,i));
    }
}
cout << *res.begin() << "\n";
return 0;
}