#include <bits/stdc++.h>
using namespace std;
long long day[3000000];
int main() {
  int n;
  cin >> n;
  int x;
  int n1 = n;
  long long sum1 = 0, sum2 = 0;
  while (n--) {
    cin >> x;
    sum1 |= x;
  }
  while (n1--) {
    cin >> x;
    sum2 |= x;
  }
  cout << sum1 + sum2 << "\n";
}
