#include <bits/stdc++.h>
using namespace std;
int a[1001], b[1001];
int sa[1001], sb[1001], s[1001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int mn = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    sa[i] = a[i];
    sb[i] = b[i];
    ans = max(sa[i] + sb[i], ans);
    for (int j = i + 1; j < n; j++) {
      sa[j] = sa[j - 1] | a[j];
      sb[j] = sb[j - 1] | b[j];
      ans = max(sa[j] + sb[j], ans);
    }
  }
  cout << ans << endl;
  return 0;
}
