#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long j = 0; j < n; j++) cin >> b[j];
  long long ans1 = INT_MIN, ans2 = INT_MIN;
  for (long long i = 0; i < n; i++) {
    long long curr_or1 = 0;
    long long curr_or2 = 0;
    for (long long j = i; j < n; j++) {
      curr_or1 = curr_or1 | a[j];
      ans1 = max(curr_or1, ans1);
      curr_or2 = curr_or2 | b[j];
      ans2 = max(curr_or2, ans2);
    }
  }
  cout << ans1 + ans2;
  return 0;
}
