#include <bits/stdc++.h>
using namespace std;
const long double eps = 0.000000005;
const long double pi = 3.1415926535897932;
const long long inf = 1e9;
int a[1010], b[1010];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) cin >> b[i];
  int s1, s2;
  for (int l = 0; l < n; l++)
    for (int r = l; r < n; r++) {
      s1 = a[l];
      s2 = b[l];
      for (int i = l + 1; i <= r; i++) {
        s1 = s1 | a[i];
        s2 = s2 | b[i];
      }
      ans = max(ans, s1 + s2);
    }
  cout << ans << endl;
  return 0;
}
