#include <bits/stdc++.h>
using namespace std;
int n, a, b, aa, bb;
int main() {
  scanf("%d", &n);
  aa = bb = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    aa |= a;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b);
    bb |= b;
  }
  printf("%d\n", aa + bb);
  return 0;
}
