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