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