using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        
        int N = int.Parse(Console.ReadLine());

        
        int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        
        int[] B = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        
        int[] prefixXor = new int[N + 1];
        for (int i = 1; i <= N; i++)
        {
            prefixXor[i] = prefixXor[i - 1] ^ A[i - 1];
        }

        long maxVal = 0;

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

                int xorValue = prefixXor[R + 1] ^ prefixXor[L];
                long currentVal = (long)xorValue * andValue;
                if (currentVal > maxVal)
                {
                    maxVal = currentVal;
                }
            }
        }

      
        Console.WriteLine(maxVal);
        Console.ReadKey();
    }
}