#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, l, m = INT_MIN;
  scanf("%d", &n);
  int a[n], b[n], aa[(n * (n + 1)) / 2], bb[(n * (n + 1)) / 2];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    m = max(a[i] + b[i], m);
  }
  for (i = 0; i < n; i++) {
    l = a[i];
    k = b[i];
    for (j = i + 1; j < n; j++) {
      l = l | a[j];
      k = k | b[j];
      m = max(m, l + k);
    }
  }
  printf("%d\n", m);
  return 0;
}
