using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] y = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        int[] xorPrefix = new int[n + 1];
        for (int i = 1; i <= n; i++)
        {
            xorPrefix[i] = xorPrefix[i - 1] ^ x[i - 1];
        }

        long maxResult = 0;
        for (int start = 1; start <= n; start++)
        {
            int currentAnd = y[start - 1];
            for (int end = start; end <= n; end++)
            {
                currentAnd &= y[end - 1];
                if (currentAnd == 0) break;

                int currentXor = xorPrefix[end] ^ xorPrefix[start - 1];
                long currentResult = (long)currentXor * currentAnd;
                maxResult = Math.Max(maxResult, currentResult);
            }
        }

        Console.WriteLine(maxResult);
    }
}