#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n;
int a[maxn], b[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int sum1 = a[i], sum2 = b[i];
    for (int j = i; j <= n; j++) {
      if (i != j) {
        sum1 |= a[j];
        sum2 |= b[j];
      }
      ans = max(sum1 + sum2, ans);
    }
  }
  cout << ans;
  return 0;
}
