using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        int[] b = new int[n];
        string[] s = Console.ReadLine().Split();
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        s = Console.ReadLine().Split();
        for (int i = 0; i < n; i++)
        {
            b[i] = int.Parse(s[i]);
        }
        long max = 0;
        int[] prefiks = new int[n + 1];
        for (int i = 0; i < n; i++)
        {
            prefiks[i + 1] = prefiks[i] ^ a[i];
        }
        for (int i = 1; i <= n; i++)
        {
            int and = b[i - 1];
            for (int j = i; j <= n; j++)
            {
                int vxor = prefiks[j] ^ prefiks[i- 1];
                and &= b[j - 1];
                long trv = (long)vxor * and;
                max = Math.Max(max, trv);
                if (and == 0)
                {
                    break;
                }
            }
        }
        Console.WriteLine(max);
        Console.ReadLine();
    }
}