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