#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

                                                                                
                                                                                    int max_value = 0;

                                                                                        
                                                                                            for (int L = 0; L < N; L++) {
                                                                                                    int andValue = B[L];  
                                                                                                            for (int R = L; R < N; R++) {
                                                                                                                        
                                                                                                                                    if (R > L) {
                                                                                                                                                    andValue &= B[R];
                                                                                                                                                                }

                                                                                                                                                                            
                                                                                                                                                                                        int hvalue = prefixH[R + 1] ^ prefixH[L];
                                                                                                                                                                                                    
                                                                                                                                                                                                                
                                                                                                                                                                                                                            int value = hvalue * andValue;
                                                                                                                                                                                                                                        max_value = max(max_value, value);
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                    }

                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                            cout << max_value << endl;

                                                                                                                                                                                                                                                                return 0;
                                                                                                                                                                                                                                                                }