#include <bits/stdc++.h>
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
int A[1005];
int B[1005];
int preA[1005];
int preB[1005];
int main() {
  int n;
  A[0] = B[0] = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    preA[i] = preA[i - 1] | A[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> B[i];
    preB[i] = preB[i - 1] | B[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int tempA = preA[j] | preA[i] | A[i];
      int tempB = preB[j] | preB[i] | B[i];
      ans = max(ans, tempA + tempB);
    }
  }
  cout << ans << endl;
  return 0;
}
