#include <bits/stdc++.h>
int n, a, b;
int A = 0, B = 0;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    A |= a;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b);
    B |= b;
  }
  printf("%d\n", A + B);
  return 0;
}
