#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a[100010], b[100010], max = 0, sumOr, sumBo;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    sumOr = a[i];
    sumBo = b[i];
    for (int j = i + 1; j <= n; j++) {
      sumOr |= a[j];
      sumBo |= b[j];
      if (sumOr + sumBo > max) max = sumOr + sumBo;
    }
    if (sumOr + sumBo > max) max = sumOr + sumBo;
  }
  cout << max << endl;
}
