#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long mx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      long long an = 0;
      long long bn = 0;
      for (int t = i; t <= j; t++) {
        an = an | a[t];
        bn = bn | b[t];
      }
      if (an + bn > mx) {
        mx = an + bn;
      }
    }
  }
  cout << mx;
}
