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