#include <bits/stdc++.h>
using namespace std;
bool sortMethod(const pair<long long int, long long int>& a,
                const pair<long long int, long long int>& b) {
  return a.second < b.second;
}
int main() {
  long long int n, a, orA = 0, orB = 0;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> a;
    orA = (orA | a);
  }
  for (long long int i = 0; i < n; i++) {
    cin >> a;
    orB = (orB | a);
  }
  cout << orA + orB << endl;
}
