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