#include <bits/stdc++.h>
int arr1[100000], arr2[100000];
int or1 = 0, or2 = 0;
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &arr1[i]);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &arr2[i]);
  }
  for (i = 0; i < n; i++) {
    or1 |= arr1[i];
    or2 |= arr2[i];
  }
  printf("%d\n", or1 + or2);
  return 0;
}
