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