#include <bits/stdc++.h>
using namespace std;
const int maxInt = 1e9 * 2;
const long long int maxLong = 1e18 * 2;
int a[1010], b[1010];
long long int f(int arr[], int l, int r) {
  long long int rs = 0;
  rs = arr[l];
  for (int i = l + 1; i <= r; i++) rs |= arr[i];
  return rs;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  long long int ans1 = 0, ans2 = 0;
  for (int l = 0; l < n; l++)
    for (int r = 0; r < n; r++)
      if (r >= l) {
        long long int one = f(a, l, r);
        long long int two = f(b, l, r);
        ans1 = max(ans1, one);
        ans2 = max(ans2, two);
      }
  cout << ans1 + ans2;
}
