#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j;
  cin >> n;
  long long a[n], b[n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  vector<long long> sum;
  long long s1, s2, l = 0, r = 0;
  for (i = 0; i < n; i++) {
    s1 = a[0];
    s2 = b[0];
    for (j = l + 1; j <= r; j++) {
      s1 = s1 | a[j];
      s2 = s2 | b[j];
    }
    r++;
    sum.push_back(s1 + s2);
  }
  cout << *max_element(sum.begin(), sum.end()) << endl;
  return 0;
}
