#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int long long n;
  cin >> n;
  std::vector<int long long> a(n), b(n);
  int long long ans1 = 0, ans2 = 0;
  for (int long long i = 0; i < n; i++) {
    cin >> a[i];
    ans1 = ans1 | a[i];
  }
  for (int long long i = 0; i < n; i++) {
    cin >> b[i];
    ans2 = ans2 | b[i];
  }
  cout << ans1 + ans2;
}
