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