#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 7, MOD = 1e9;
long long cnt = 0;
long long arr[M], arrr[M];
long long sum, sum1, mx = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  for (int i = 0; i < t; i++) cin >> arr[i];
  for (int i = 0; i < t; i++) {
    cin >> arrr[i];
  }
  for (int i = 0; i < t; i++) {
    sum = arr[i];
    sum1 = arrr[i];
    mx = max(mx, sum + sum1);
    for (int j = i + 1; j < t; j++) {
      sum = sum | arr[j];
      sum1 = sum1 | arrr[j];
      mx = max(mx, sum + sum1);
    }
  }
  cout << mx << endl;
  return 0;
}
