#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, n, p, flag, sum1, sum2, y, ans;
  std::cin >> n;
  int ar[n], br[n];
  for (i = 0; i < n; i++) std::cin >> ar[i];
  for (i = 0; i < n; i++) cin >> br[i];
  flag = 0;
  ans = -10000000000000000;
  for (i = 0; i < n; i++) {
    for (j = 1; j <= n - i; j++) {
      sum1 = 0;
      sum2 = 0;
      for (k = j - 1; k < j + i; k++) {
        sum1 |= ar[k];
        sum2 |= br[k];
      }
      ans = max(ans, sum1 + sum2);
    }
  }
  cout << ans;
}
