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

namespace Dva_niza___Petlja_2024
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, br = 0, br1 = 0, br2 = 0;
            string unos = Console.ReadLine();
            N = Convert.ToInt32(unos);

            int[] A = new int[N], B = new int[N];

            unos = Console.ReadLine(); unos += " ";
            for (int i = 0; i < unos.Length; i++)
            {
                if (unos[i] == ' ')
                {
                    A[br++] = Convert.ToInt32(unos.Substring(br1, br2));
                    br1 = i + 1; br2 = 0;
                }
                else br2++;
            }

            br = 0; br1 = 0;
            unos = Console.ReadLine(); unos += " ";
            for (int i = 0; i < unos.Length; i++)
            {
                if (unos[i] == ' ')
                {
                    B[br++] = Convert.ToInt32(unos.Substring(br1, br2));
                    br1 = i + 1; br2 = 0;
                }
                else br2++;
            }

            int max = 0;

            for (int L = 0; L <= N / 2; L++)
                for (int R = N - 1; R >= L; R--)
                {
                    br = (A[L] ^ A[R]) * (B[L] & B[R]);
                    if (max < br) max = br;
                }

            Console.WriteLine(max);

            Console.ReadLine();
        }
    }
}