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