#include <bits/stdc++.h>
int a[1005], b[1005], n;
int dfs(int i, int x, int y) {
  if (i == n) return x + y;
  return dfs(i + 1, x | a[i], y | b[i]);
}
int main() {
  int 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++) {
    int t = dfs(i, 0, 0);
    if (t > ans) ans = t;
  }
  printf("%d", ans);
}
