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

namespace Zadatak_5_dva_niza_
{
    internal class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            ulong[] A = new ulong[N];
            ulong[] B = new ulong[N];
            string[] input = Console.ReadLine().Split(' ');
            for (long i = 0; i < N; i++)
            {
                A[i] = ulong.Parse(input[i]);
            }
            input = Console.ReadLine().Split(' ');
            for (long i = 0; i < N; i++)
            {
                B[i] = ulong.Parse(input[i]);
            }
            HashSet<ulong> results = new HashSet<ulong>();
            for (int i = 0; i < N; i++)
            {
                ulong Asum = A[i];
                ulong Bsum = B[i];
                for (int j = i+1; j < N; j++)
                {
                    Asum = Asum ^ A[j];
                    Bsum = Bsum & B[j]; 
                }
                
                results.Add(Asum * Bsum);
            }
            Console.WriteLine(results.Max());
            
            
       }
        
   }
}