using System;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

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

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

        long maxResult = 0;

        int[] prefixXor = new int[n + 1];
        prefixXor[0] = 0;

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

        for (int l = 1; l <= n; l++)
        {
            int currentAnd = B[l - 1];

            for (int r = l; r <= n; r++)
            {
                int currentXor = prefixXor[r] ^ prefixXor[l - 1];

                currentAnd &= B[r - 1];

                long value = (long)currentXor * currentAnd;

                maxResult = Math.Max(maxResult, value);

                
                if (currentAnd == 0) break;
            }
        }

        Console.WriteLine(maxResult);
    }
}