#include <bits/stdc++.h>
using namespace std;
long long int n, a[10000000], b[10000000], sum1, sum2;
long long int r, f;
int main() {
  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++) {
    for (int j = i; j <= n; j++) {
      sum1 = a[i];
      for (int k = i; k <= j; k++) {
        sum1 |= a[k];
      }
      f = max(sum1, f);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      sum2 = b[i];
      for (int k = i; k <= j; k++) {
        sum2 |= b[k];
      }
      r = max(sum2, r);
    }
  }
  cout << r + f;
}
