#include <bits/stdc++.h>
using namespace std;
int n, x, y, temp;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &temp), x |= temp;
  for (int i = 0; i < n; i++) scanf("%d", &temp), y |= temp;
  printf("%d", x + y);
}
