#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.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 maxi=0;
    int a1, b1;
    for (int i =0; i<n; i++){
        a1=a[i];
        b1=b[i];
        for (int j = i+1; j<n; j++){
            if (maxi<(a1^a[j])*(b1&b[j])){
                maxi=(a1^a[j])*(b1&b[j]);
            }
            a1=(a1^a[j]);
            b1=(b1&b[j]);
        }
    }
    cout << maxi;

    return 0;
}