#include <bits/stdc++.h>
using namespace std;
int func(int arr[], int l, int r) {
  int ans = arr[l];
  for (int i = l + 1; i <= r; i++) ans = arr[i] | ans;
  return ans;
}
int main() {
  int n, a[1005], b[1005], sum = 0, max_sum = 0, l1, r1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  {
    sum = func(a, 1, n) + func(b, 1, n);
    if (sum > max_sum) {
      max_sum = sum;
    }
  }
  cout << max_sum << endl;
}
