#include <bits/stdc++.h>
using namespace std;
int n, a[1000001], b[1000001], x, y, ans;
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++) {
    ans = 0;
    for (int j = i; j <= n; j++) {
      x = x | a[j];
      y = y | b[j];
      ans = max(ans, x + y);
    }
  }
  cout << ans;
  return 0;
}
