#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long i, j, sum, ar[1005], br[1005], mx, nwa, nwb, n;
  while (cin >> n) {
    for (i = 0; i < n; i++) {
      cin >> ar[i];
    }
    for (i = 0; i < n; i++) {
      cin >> br[i];
    }
    mx = 0;
    for (i = 0; i < n; i++) {
      nwa = ar[i];
      nwb = br[i];
      sum = ar[i] + br[i];
      mx = max(sum, mx);
      for (j = i + 1; j < n; j++) {
        nwa = (nwa | ar[j]);
        nwb = (nwb | br[j]);
        sum = nwa + nwb;
        mx = max(sum, mx);
      }
    }
    cout << mx << endl;
  }
  return 0;
}
