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