#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
void dout(string name, T arg) {
  cerr << arg << endl;
}
template <typename T1, typename... T2>
void dout(string names, T1 arg, T2... args) {
  cerr << arg << " | ";
  dout(names.substr(names.find(',') + 2), args...);
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int mx = 1e6 + 5;
const int INF = 1000000007;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y >>= 1;
    x = (x * x) % 1000000007;
  }
  return (res % 1000000007);
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n);
  cin >> a >> b;
  long long ans = 0;
  long long currA = a[0], currB = b[0];
  for (int i = 1; i < n; i++) {
    currA |= a[i];
    currB |= b[i];
  }
  cout << currA + currB;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
