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