import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arrayA = new int[n];
        int[] arrayB = new int[n];
        int res = 0;
        for (int i = 0; i < n; i++) {
            arrayA[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            arrayB[i] = sc.nextInt();
        }
        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);
        sc.close();
    }
}