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