#include <bits/stdc++.h>
using namespace std;
int a[1001] = {0}, b[1001] = {0};
int main() {
  int n, a_sum = 0, b_sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a_sum |= a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    b_sum |= b[i];
  }
  cout << a_sum + b_sum;
  return 0;
}
