#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  long long a[n], b[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 mx1 = -1;
  for (int i = 0; i < n; i++) {
    long long cn = 0;
    for (int j = i; j < n; j++) {
      cn = cn | a[j];
      if (mx1 < cn) mx1 = cn;
    }
  }
  long long mx2 = -1;
  for (int i = 0; i < n; i++) {
    long long cn = 0;
    for (int j = i; j < n; j++) {
      cn = cn | b[j];
      if (mx2 < cn) mx2 = cn;
    }
  }
  printf("%lld\n", mx1 + mx2);
  return 0;
}
