#include <bits/stdc++.h>
int main() {
  int length_of_arrays;
  scanf("%i", &length_of_arrays);
  long long input_a, input_b;
  long long max_a = 0, max_b = 0;
  for (int counter = 0; counter < length_of_arrays; counter++) {
    scanf("%I64d", &input_a);
    max_a |= input_a;
  }
  for (int counter = 0; counter < length_of_arrays; counter++) {
    scanf("%I64d", &input_b);
    max_b |= input_b;
  }
  printf("%I64d", max_a + max_b);
  printf("\n");
  return 0;
}
