#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  ;
  ll n, x, i, ans1 = 0, ans2 = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    ans1 |= x;
  }
  for (i = 0; i < n; i++) {
    cin >> x;
    ans2 |= x;
  }
  cout << ans1 + ans2 << "\n";
  return 0;
}
