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