#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int tam;
  vector<int> v1, v2;
  scanf("%lld", &tam);
  for (int i = 0, x; i < tam; i++) {
    scanf("%d", &x);
    v1.push_back(x);
  }
  for (int i = 0, x; i < tam; i++) {
    scanf("%d", &x);
    v2.push_back(x);
  }
  int s1 = 0, s2 = 0, maxi = 0;
  for (int i = 0; i < tam; i++) {
    for (int j = i; j <= i; j++) {
      s1 |= v1[j];
      s2 |= v2[j];
      maxi = max(s1 + s2, maxi);
    }
  }
  printf("%d\n", maxi);
  return 0;
}
