#include <iostream>
#include <vector>
#include <algorithm> // for std::max
using namespace std;

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

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

    int r = n - 1;
    int l = 0;
    int maxpamti = 0;

    while (r >= 0) {
        while (l < n) {
            int xora = 0;
            int andb = -1;

            for (int x = l; x <= r; x++) {
                xora = xora ^ a[x];
                if (andb >= 0) 
                    andb = andb & b[x];
                else 
                    andb = b[x];
            }

            int tren = xora * andb;
            maxpamti = max(maxpamti, tren);

            l++;
        }
        l = 0;
        r--;
    }

    cout << maxpamti << endl;
    return 0;
}