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