#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int n;
  cin >> n;
  long long int answer = 0;
  long long int val1 = 0;
  long long int j;
  for (j = 0; j < n; j++) {
    long long int x;
    cin >> x;
    val1 = val1 | x;
  }
  long long int val2 = 0;
  for (j = 0; j < n; j++) {
    long long int x;
    cin >> x;
    val2 = val2 | x;
  }
  answer = val1 + val2;
  cout << answer << endl;
}
