#include <bits/stdc++.h>
using namespace std;
long long n, ans1[1005][1005], ans2[1005][1005], ans, l, r, mx;
long long arr[100005], b[100005];
int main() {
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &arr[i]);
  for (int i = 1; i <= n; i++) scanf("%I64d", &b[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans1[i][j] = ans1[i][j - 1] | arr[j];
      ans2[i][j] = ans2[i][j - 1] | b[j];
      ans = ans1[i][j] + ans2[i][j];
      if (ans > mx) mx = ans;
    }
  }
  printf("%I64d", mx);
  return 0;
}
