#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 1010;
int a[N], b[N];
int main(void) {
  int n, i, j, maxm;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (i = 0; i < n; ++i) scanf("%d", &b[i]);
  maxm = -1;
  for (i = 0; i < n; ++i) {
    int ta = a[i], tb = b[i];
    for (j = i; j < n; ++j) {
      ta |= a[j];
      tb |= b[j];
      if (ta + tb > maxm) maxm = ta + tb;
    }
  }
  printf("%d\n", maxm);
  return 0;
}
