#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  n++;
  int *a = new int[n];
  int *b = new int[n];
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    a[i] |= a[i - 1];
  }
  for (int i = 1; i < n; i++) {
    cin >> b[i];
    b[i] |= b[i - 1];
  }
  int maxXor = 0;
  for (int i = 1; i < n; i++)
    for (int j = i; j < n; j++)
      maxXor = max(maxXor, (a[i - 1] | a[j]) + (b[i - 1] | b[j]));
  cout << maxXor << endl;
  return 0;
}
