#include <bits/stdc++.h>
using namespace std;
int str[5005], stolb[5005], color[5005];
int n, a, x, y;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a, x |= a;
  for (int i = 0; i < n; ++i) cin >> a, y |= a;
  cout << x + y;
  return 0;
}
