#include <iostream>
using namespace std;

int main()
{
    unsigned long int N;
    cin >> N;
    unsigned long long int a[N], b[N], r;
    unsigned long int max = 0;
    unsigned long int x = 0;
    unsigned long int y = 1;
    for(unsigned long int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(unsigned long int i = 0; i < N; i++){
        cin >> b[i];
    }
    for(unsigned long int i = 0; i < N - 1; i++){
        for(unsigned long int j = i + 1; j < N; j++){
            for(unsigned long int l = i; l <= j; l++){
                x = x^a[l];
                y = y&b[l];
            }
            r = x * y;
            x = 0;
            y = 1;
            if(r > max)
                max = r;
        }
    }
    cout << max;

    return 0;
}