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