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

namespace _5.Dva_Niza
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            int[] b = new int[n];
            string[] nizA = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(nizA[i]);
            }
            string[] nizB = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                b[i] = int.Parse(nizB[i]);
            }
            int max = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = i; j < n; j++)
                {
                    int xor = a[i] ^ a[j];
                    int and = b[i] & b[j];
                    if ((xor * and) > max)
                        max = xor * and;
                }
            }
            Console.WriteLine(max);
            Console.ReadKey();
        }
    }
}