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