#include <bits/stdc++.h>
int main() {
  int num;
  std::cin >> num;
  int arr1[num], arr2[num], sum1 = 0, sum2 = 0;
  for (int i = 0; i < num; i++) {
    std::cin >> arr1[i];
    sum1 |= arr1[i];
  }
  for (int i = 0; i < num; i++) {
    std::cin >> arr2[i];
    sum2 |= arr2[i];
  }
  std::cout << sum1 + sum2 << std::endl;
  return 0;
}
