#include <bits/stdc++.h>
using namespace std;
const double g = 10.0, eps = 1e-7;
const int N = 1000 + 10, maxn = 60000 + 10, inf = 0x3f3f3f3f;
long long a[N], b[N];
long long sa[N], sb[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
  for (int i = 1; i <= n; i++) sa[i] = sa[i - 1] | a[i];
  for (int i = 1; i <= n; i++) sb[i] = sb[i - 1] | b[i];
  long long ans = -1e18;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      ans = max(ans, (sa[i] | sa[j]) + (sb[i] | sb[j]));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
