#include <bits/stdc++.h>
using namespace std;
int n;
long long a[1111], b[1111];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%lld", &b[i]);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    long long aa = 0, bb = 0;
    for (int j = i; j < n; ++j) {
      aa |= a[j];
      bb |= b[j];
    }
    ans = max(ans, aa + bb);
  }
  printf("%lld\n", ans);
  return 0;
}
