#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  int aa = 0, bb = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    aa |= a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    bb |= b[i];
  }
  cout << aa + bb;
  return 0;
}
