#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;

    int* a = new int[n];
    int* b = new int[n];

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }

    int max = 0;
    for (int l = 0; l < n; l++)
    {
        for (int r = 0; r < n; r++)
        {
            int trenutni = (a[l] ^ a[r]) * (b[l] & b[r]);
            if(trenutni > max)
            {
                max = trenutni;
            }
        }
    }

    cout << max;
    
    delete[] a;
    delete[] b;

    return 0;
}