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