#include <bits/stdc++.h>
using namespace std;
int a[1005];
int b[1005];
int revisa(int low, int high) {
  int sum = 0, suma = 0;
  for (int i = low; i <= high; i++) sum |= a[i];
  for (int i = low; i <= high; i++) suma |= b[i];
  return suma + sum;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int mayor = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      int ans = revisa(i, j);
      mayor = ans > mayor ? ans : mayor;
    }
  cout << mayor << '\n';
}
