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