#include <bits/stdc++.h>
using namespace std;

main() {
    int n, i, j, k, maksimalna = 0, xr = 0, andd = 0, sad;
    
    cin >> n;

    int a[n], b[n];
    
    for(i=0; i<n; i++) {
        cin >> a[i];
    }

    for(i=0; i<n; i++) {
        cin >> b[i];
    }

    for(j=0; j<n; j++) {
        for (k=j; k<n; k++) {
        	xr = 0;
        	andd = b[j];
            xr = xr ^ a[k]; 
            andd = andd & b[k];
            sad = xr * andd;
            maksimalna = sad + 1;
            break;
        }
    }

    cout << maksimalna;
}