#include <bits/stdc++.h>
int f(int *aa, int l, int r) {
  int i, x;
  x = 0;
  for (i = l; i <= r; i++) x |= aa[i];
  return x;
}
int main() {
  static int aa[1000], bb[1000];
  int n, i, l, r, max;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &aa[i]);
  for (i = 0; i < n; i++) scanf("%d", &bb[i]);
  max = 0;
  for (l = 0; l < n; l++)
    for (r = l; r < n; r++) {
      int x;
      if (max < (x = f(aa, l, r) + f(bb, l, r))) max = x;
    }
  printf("%d\n", max);
  return 0;
}
