import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] arrayA = new int[n];
        int[] arrayB = new int[n];
        String[] arrayBinaryA = sc.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            arrayA[i] = Integer.parseInt(arrayBinaryA[i]);
        }
        String[] arrayBinaryB = sc.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            arrayB[i] = Integer.parseInt(arrayBinaryB[i]);
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int xor = arrayA[i] ^ arrayA[j];
                int and = arrayB[i] & arrayB[j];
                if ((xor * and) > res) {
                    res = xor * and;
                }
            }
        }
        System.out.println(res);
    }
}