#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  long long ar[n], br[n];
  for (long long i = 0; i < n; i++) scanf("%lld", &ar[i]);
  for (long long i = 0; i < n; i++) scanf("%lld", &br[i]);
  long long mx = INT_MIN;
  for (long long i = 0; i < n; i++) {
    long long foo = ar[i];
    long long bar = br[i];
    mx = max(mx, (foo + bar));
    for (long long j = i + 1; j < n; j++) {
      foo = foo | ar[j];
      bar = bar | br[j];
      mx = max(mx, (foo + bar));
    }
  }
  printf("%lld\n", mx);
  return 0;
}
