#include <bits/stdc++.h>
using namespace std;
int a[1000], b[1000];
int analyze(int left, int right);
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) ans = max(ans, analyze(i, j));
  }
  printf("%d\n", ans);
}
int analyze(int left, int right) {
  int sum1 = a[left], sum2 = b[left];
  for (int i = left + 1; i <= right; i++) sum1 |= a[i], sum2 |= b[i];
  return sum1 + sum2;
}
