#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[1100], b[1100];
  int i, l, r;
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
    }
    if (n == 1) {
      printf("%d\n", a[1] + b[1]);
    } else {
      int max = 0;
      int u, v;
      for (l = 1; l <= n; l++) {
        u = a[l];
        v = b[l];
        for (r = l; r <= n; r++) {
          u = (u | a[r]);
          v = (v | b[r]);
          if (u + v > max) max = u + v;
        }
      }
      printf("%d\n", max);
    }
  }
  return 0;
}
