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