#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
bool isprime(long long n) {
  if (n % 2 == 0) {
    return false;
  }
  for (auto i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long digitsum(long long n) {
  long long sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
long long Cnk(long long n, long long k) {
  long long B[n + 1][n + 1];
  for (long long i = 0; i <= n; ++i) {
    B[i][0] = 1;
    B[i][i] = 1;
    for (long long j = 1; j < i; ++j) B[i][j] = B[i - 1][j - 1] + B[i - 1][j];
  }
  return B[n][k];
}
int pow(int a, int b) {
  int r = 1;
  for (auto i = 0; i < b; i++) r *= a;
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n, a = 0, b = 0, x;
  cin >> n;
  for (auto i = 0; i < n; i++) {
    cin >> x;
    a |= x;
  }
  for (auto i = 0; i < n; i++) {
    cin >> x;
    b |= x;
  }
  cout << a + b;
}
