#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
const int inf = 2e9;
const long long linf = 5000000000000000000;
const long double LDINF = 2e18;
template <typename T>
void print(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
  cout << '\n';
}
template <typename T>
void print(deque<T>& a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
  cout << '\n';
}
template <typename T>
void print(vector<vector<T>>& a) {
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << ' ';
    cout << '\n';
  }
}
template <typename T>
void input(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) cin >> a[i];
}
template <typename T>
void input(deque<T>& a) {
  for (int i = 0; i < a.size(); i++) cin >> a[i];
}
template <typename T>
void input(vector<vector<T>>& a) {
  for (int i = 0; i < a.size(); i++)
    for (int j = 0; j < a[i].size(); j++) cin >> a[i][j];
}
long long mod = 998244353;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
vector<int> p, rang;
void CreateSet(int v) {
  p[v] = v;
  rang[v] = 1;
}
int FindSet(int v) {
  if (p[v] == v) return v;
  return p[v] = FindSet(p[v]);
}
vector<pair<int, int>> ans;
void UnionSet(int a, int b) {
  a = FindSet(a);
  b = FindSet(b);
  if (a == b) return;
  if (rang[a] < rang[b]) swap(a, b);
  p[b] = a;
  if (rang[a] == rang[b]) rang[a]++;
  ans.push_back({a, b});
}
void solve() {
  long long n, d;
  cin >> n;
  long long a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    cin >> d;
    a |= d;
  }
  for (int i = 0; i < n; i++) {
    cin >> d;
    b |= d;
  }
  cout << a + b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tst = 1;
  while (tst--) solve();
}
