#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = 2 * acos((long double)0);
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
void setmin(int& a, int val) {
  if (a > val) a = val;
}
void setmax(int& a, int val) {
  if (a < val) a = val;
}
void solve() {
  int(n);
  scanf("%d", &n);
  int x = 0, y = 0;
  for (int i = 0; i < (n); ++i) {
    int(a);
    scanf("%d", &a);
    x |= a;
  }
  for (int i = 0; i < (n); ++i) {
    int(a);
    scanf("%d", &a);
    y |= a;
  }
  printf("%d\n", x + y);
}
int main() {
  solve();
  return 0;
}
