#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, a[1001], b[1001], mx = 0, x1, x2;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (i = 0; i < n; i++) {
    for (j = i; j < n; j++) {
      x1 = a[i];
      x2 = b[i];
      for (k = i + 1; k <= j; k++) {
        x1 = (x1 | a[k]);
        x2 = (x2 | b[k]);
      }
      mx = max(mx, x1 + x2);
    }
  }
  cout << mx << endl;
  return 0;
}
