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