#include <bits/stdc++.h>
using namespace std;
long long fx4[] = {+1, -1, +0, +0};
long long fy4[] = {+0, +0, +1, -1};
long long fx8[] = {+0, +0, +1, -1, -1, +1, -1, +1};
long long fy8[] = {-1, +1, +0, +0, +1, +1, -1, -1};
long long bigmod(long long a, long long b) {
  long long ret = 1LL;
  while (b) {
    if (b & 1) ret = (ret * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ret;
}
long long inverse(long long n) { return bigmod(n, 1000000007 - 2); }
long long gcd(long long a, long long b) { return (b != 0 ? gcd(b, a % b) : a); }
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
long long n, v[37];
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(0);
  long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, w, x,
      y, z, cnt, sum, total, ar[1005], br[1005], cr[1005], row, col, nx, ny, hi,
      lo, mid, ans, tc;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (i = 0; i < n; i++) {
    cin >> br[i];
  }
  sum = 0;
  for (i = 0; i < n; i++) {
    s = 0;
    m = 0;
    p = 0;
    for (j = 0; j < n; j++) {
      s = s | ar[j];
      m = m | br[j];
      p = max(p, s + m);
    }
    sum = max(p, sum);
  }
  cout << sum << endl;
}
