#include <bits/stdc++.h>
using namespace std;
int n;
int a[1005], b[1005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  int s1, s2, ans = 0;
  for (int l = 1; l <= n; ++l) {
    s1 = 0;
    s2 = 0;
    for (int r = l; r <= n; ++r) {
      s1 |= a[r];
      s2 |= b[r];
      if (s1 + s2 > ans) ans = s1 + s2;
    }
  }
  printf("%d\n", ans);
  return 0;
}
