#include <bits/stdc++.h>
using namespace std;
int n, a[1001], b[1001], s, sum;
int f(int array[], int inceput, int sfarsit) {
  s = 0;
  for (int i = inceput; i <= sfarsit; i++) {
    s = (s | array[i]);
  }
  return s;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int suma = 0;
      suma = f(a, i, j) + f(b, i, j);
      if (sum < suma) {
        sum = suma;
      }
    }
  }
  cout << sum;
}
