#include <bits/stdc++.h>
int main() {
  long long int i, j, k, m, n, b;
  int arr[1000000], arr1[1000000];
  while (scanf("%I64d", &n) == 1) {
    k = 0, m = 0, b = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
    }
    for (j = 0; j < n; j++) {
      scanf("%d", &arr1[j]);
    }
    for (i = 0; i < n; i++) {
      k = k | arr[i];
      m = m | arr1[i];
      if ((k + m) > b) b = k + m;
    }
    printf("%I64d", b);
  }
}
