#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    a |= temp;
  }
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    b |= temp;
  }
  cout << a + b << endl;
  return 0;
}
