#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 i = 0; i < n; i++) {
    cin >> b[i];
  }
  int mx = a[0] + b[0];
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n - i; j++) {
      int x = a[i], y = b[i];
      for (int k = i + 1; k <= i + j; k++) {
        x |= a[k];
        y |= b[k];
      }
      mx = max(mx, x + y);
    }
  }
  cout << mx << endl;
}
