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

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            uint[] a = new uint[n];
            uint[] b = new uint[n];
            string[] sa = Console.ReadLine().Split(' ');
            string[] sb = Console.ReadLine().Split(' ');
            for(int i = 0; i < n; i++)
            {
                a[i] = uint.Parse(sa[i]);
                b[i] = uint.Parse(sb[i]);
            }
            uint[] memoa = new uint[n];
            uint[] memob = new uint[n];
            memoa[0] = a[0];
            memob[0] = b[0];
            bool jelPodniza = false;
            bool jelPodnizb = false;
            for(int i = 0; i < n - 1; i++)
            {
                if (((a[i + 1] ^ memoa[i]) > a[i + 1]) || (i == n - 2 && !jelPodniza)) 
                {
                    memoa[i + 1] = a[i + 1] ^ memoa[i];
                    jelPodniza = true;
                }
                else
                {
                    memoa[i + 1] = a[i + 1];
                }

                if (((b[i + 1] & memob[i]) > b[i + 1]) || (i == n - 2 && !jelPodnizb))
                {
                    memob[i + 1] = b[i + 1] & memob[i];
                    jelPodnizb = true;
                }
                else
                {
                    memob[i + 1] = b[i + 1];
                }
            }
            Console.WriteLine(memob[n - 1] * memoa[n - 1]);
        }
    }
}