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