#include <bits/stdc++.h>
using namespace std;
long long int pmod(long long int x, long long int y) {
  long long int res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long int dp1[1002][1002], dp2[1003][1003];
int main() {
  int n;
  cin >> n;
  long long int arr[n + 2];
  long long int brr[n + 2];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) cin >> brr[i];
  long long int ans1 = -1, ans2 = -1;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (i == j) {
        dp1[i][j] = arr[i];
        dp2[i][j] = brr[i];
        ans1 = max(ans1, dp1[i][j]);
        ans2 = max(ans2, dp2[i][j]);
      } else {
        dp1[i][j] = dp1[i][j - 1] | arr[j];
        dp2[i][j] = dp2[i][j - 1] | brr[j];
        ans1 = max(ans1, dp1[i][j]);
        ans2 = max(ans2, dp2[i][j]);
      }
    }
  }
  cout << ans1 + ans2;
  return 0;
}
