#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define MOD 1000000007 // 998244353
#define FIO                \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

int main()
{
	FIO
	ll n; cin >> n;
	vector<ll> a(n), b(n);
	forn(i, n)
		cin >> a[i];
	forn(i, n)
		cin >> b[i];
	
	vector<ll> prefixSum(n+1, 0);
	forn1(i, n+1)
		prefixSum[i] = prefixSum[i-1] ^ a[i-1];
	
	ll mx = 0;	
	forn(l, n)
	{
		ll start = b[l];
		for (ll r = l; r < n; r++)
		{
			start &= b[r];
			//cout << "S " << start << endl;
			ll zor = prefixSum[r+1] ^ prefixSum[l];
			//cout << zor << endl;
			mx = max(mx, start * zor);
			if (start == 0)
				break;
		}
	}
	cout << mx << endl;
}