#include <bits/stdc++.h>
using namespace std;
int f(int *x, int l, int r) {
  int sum = x[l];
  for (int i = l + 1; i <= r; i++) {
    sum |= x[i];
  }
  return sum;
}
int a[1010], b[1010];
int main() {
  int f(int *x, int l, int r);
  int n;
  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 max1 = 0;
  for (int l = 1; l <= n; l++) {
    for (int r = l; r <= n; r++) {
      if (max1 < f(a, l, r) + f(b, l, r)) max1 = f(a, l, r) + f(b, l, r);
    }
  }
  printf("%d\n", max1);
  return 0;
}
