#include <bits/stdc++.h>
int max(int *a, int *b, int length) {
  int l, r;
  int biggest = 0;
  for (l = 0; l < length; l++) {
    int curA = 0;
    int curB = 0;
    for (r = l; r < length; r++) {
      curA |= a[r];
      curB |= b[r];
      if ((curA + curB) > biggest) {
        biggest = curA + curB;
      }
    }
  }
  return biggest;
}
int main(int argc, char **argv) {
  int len;
  std::cin >> len;
  int *a = new int[len];
  int *b = new int[len];
  int i;
  for (i = 0; i < len; i++) {
    std::cin >> a[i];
  }
  for (i = 0; i < len; i++) {
    std::cin >> b[i];
  }
  std::cout << max(a, b, len) << std::endl;
  delete a;
  delete b;
  return 0;
}
