#include <iostream>
#define ll long long
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  ll a[n], b[n];
  bool a1=true;
  for (int i=0; i<n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] != 1) a1 = false;
  }
  for (int i=0; i<n; i++) scanf("%lld", &b[i]);

  if (a1) {
    ll maxb = -1;
    for (auto el : b) {
      if (el > maxb) maxb = el;
    }
    printf("%lld", maxb);
    return 0;
  }

  
  ll res = 0;
  ll xorv, andv, val;
  for (int l=0; l<n; l++) {
    xorv = 0;
    andv = (1ll << 32)-1;
    for (int r=l; r<n; r++) {
      xorv = xorv^a[r];
      andv = andv&b[r];
      val = xorv * andv;
      if (val > res) res = val;
    }
  }
  printf("%lld", res);
}