#include <iostream>
#include <vector>
#include <climits>
using namespace std;

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

    vector<int> A(N + 1, 0), B(N + 1, 0);
    for (int i = 1; i <= N; i++) cin >> A[i];
    for (int i = 1; i <= N; i++) cin >> B[i];

    vector<int> prefixXOR(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        prefixXOR[i] = prefixXOR[i - 1] ^ A[i];
    }

    long long maxValue = 0;

    for (int L = 1; L <= N; L++) {
        int currentAND = B[L];
        for (int R = L; R <= N; R++) {
            currentAND &= B[R];
            if (currentAND == 0) break;
            int currentXOR = prefixXOR[R] ^ prefixXOR[L - 1];
            maxValue = max(maxValue, (long long)currentXOR * currentAND);
        }
    }

    cout << maxValue << endl;
    return 0;
}