#include <bits/stdc++.h>
using namespace std;
int a[1005], b[1005];
int main() {
  int n;
  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]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int p = 0;
    int q = 0;
    for (int j = i; j < n; j++) {
      p |= a[j];
      q |= b[j];
      ans = max(ans, p + q);
    }
  }
  printf("%d\n", ans);
  return 0;
}
