#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  unsigned long long n, sum = 0, sum1 = 0, a, b;
  cin >> n;
  for (unsigned long long i = 0; i < n; i++) {
    cin >> a;
    sum = sum | a;
  }
  for (unsigned long long i = 0; i < n; i++) {
    cin >> b;
    sum1 = sum1 | b;
  }
  cout << sum + sum1 << "\n";
  return 0;
}
