#include <bits/stdc++.h>
using namespace std;
inline void fast_and_furious() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int n;
long long a[1005], b[1005], u, l, ans;
int main() {
  fast_and_furious();
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  ans = 0;
  for (int i = 0; i < n; i++) {
    u = l = 0;
    for (int j = i; j < n; j++) {
      u = u | a[j];
      l = l | b[j];
      ans = max(u + l, ans);
    }
  }
  cout << ans << "\n";
  return 0;
}
