#include <bits/stdc++.h>
int main() {
  int a[32] = {0}, b, i, n, j, s = 0, s1 = 0;
  scanf("%d", &n);
  for (i = 31; i >= 0; i--) a[i] = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &b);
    j = 0;
    while (b) {
      if (b & 1) a[j] = 1;
      j++;
      b >>= 1;
    }
  }
  for (i = 31; i >= 0; i--) {
    s *= 2;
    s += a[i];
    a[i] = 0;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &b);
    j = 0;
    while (b) {
      if (b & 1) a[j] = 1;
      j++;
      b >>= 1;
    }
  }
  for (i = 31; i >= 0; i--) {
    s1 *= 2;
    s1 += a[i];
  }
  printf("%d", s + s1);
}
