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

int main() {
    int n;
    scanf("%d", &n);

    int a[n], b[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++) {
        scanf("%d", &b[i]);
    }

    int t = -1;
    int calc1, calc2;
    for(int l = 0; l < n; l++) {
        calc1 = 0, calc2 = b[l];
        for(int r = l; r < n; r++) {
            calc1 = calc1 ^ a[r];
            calc2 = calc2 & b[r];
            if (calc2 == 0)
                break;
            t = max(t, calc1 * calc2);
        }
    }

    printf("%d", t);
    return 0;
}