#include <bits/stdc++.h>
using namespace std;
long long a[1111], b[1111];
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (long long i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  long long x, y, ans = 0;
  for (long long l = 1; l <= n; ++l) {
    x = a[l];
    y = b[l];
    ans = max(x + y, ans);
    for (long long r = l + 1; r <= n; ++r) {
      x |= a[r];
      y |= b[r];
      ans = max(x + y, ans);
    }
  }
  cout << ans;
  return 0;
}
