#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main() {
  int n;
  cin >> n;
  ull tmp, resf = 0;
  for (int rep = 0; rep < 2; ++rep) {
    ull res1 = 0;
    for (int i = 0; i < n; ++i) {
      cin >> tmp;
      res1 |= tmp;
    }
    resf += res1;
  }
  cout << resf << endl;
}
