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