#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x3f3f3f3f;
const int M = 1000 + 5;
int main() {
  int a[M], b[M], i, j, MAX, n;
  while (~scanf("%d", &n)) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (i = 1; i <= n; i++) scanf("%d", &b[i]);
    for (i = 1; i <= n; i++) a[i] = a[i] | a[i - 1];
    for (j = 1; j <= n; j++) b[j] = b[j] | b[j - 1];
    MAX = -INF;
    a[0] = a[n + 1] = b[0] = b[n + 1] = 0;
    for (i = 1; i <= n; i++) {
      for (j = i; j <= n; j++)
        MAX = ((MAX) > ((a[j] | a[i - 1]) + (b[j] | b[i - 1]))
                   ? (MAX)
                   : ((a[j] | a[i - 1]) + (b[j] | b[i - 1])));
    }
    printf("%d\n", MAX);
  }
  return 0;
}
