#include <bits/stdc++.h>
using namespace std;
long long n, a[1005], b[1005], i, j, tem1, tem2, ans;
int main() {
  scanf("%I64d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%I64d", &a[i]);
  }
  for (i = 0; i < n; ++i) scanf("%I64d", &b[i]);
  for (i = 0; i < n; ++i) {
    tem1 = 0;
    tem2 = 0;
    for (j = i; j < n; ++j) {
      tem1 |= a[j];
      tem2 |= b[j];
      ans = max(ans, tem1 + tem2);
    }
  }
  cout << ans;
  return 0;
}
