#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long sum1 = 0;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    sum1 = sum1 | a;
  }
  long long sum2 = 0;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    sum2 = sum2 | a;
  }
  long long ans = sum1 + sum2;
  cout << ans << endl;
}
