#include <bits/stdc++.h>
using namespace std;
long long int n, a[1006], b[1006], nmt;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  if (n == 1) {
    cout << a[1] + b[1];
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    long long int cnt, lnt, mx, mx1;
    cnt = a[i];
    lnt = b[i];
    mx = 0;
    mx1 = 0;
    for (int j = i + 1; j <= n; j++) {
      lnt = (b[j] | lnt);
      cnt = (a[j] | cnt);
      mx = cnt + lnt;
      mx1 = max(mx1, mx);
    }
    nmt = max(mx1, nmt);
  }
  cout << nmt << endl;
}
