#include <bits/stdc++.h>
using namespace std;
int sum1, sum2;
int main() {
  int n, x;
  cin >> n;
  cin >> x;
  sum1 = x;
  for (int i = 1; i < n; i++) {
    cin >> x;
    sum1 |= x;
  }
  int y;
  cin >> y;
  sum2 = y;
  for (int i = 1; i < n; i++) {
    cin >> y;
    sum2 |= y;
  }
  cout << sum1 + sum2;
}
