#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1], b[n + 1];
  a[0] = b[0] = 0;
  for (__typeof(n + 1) i = (1); i != (n + 1); i++) cin >> a[i];
  for (__typeof(n + 1) i = (1); i != (n + 1); i++) cin >> b[i];
  int ans = 0;
  for (__typeof(n + 1) i = (1); i != (n + 1); i++) {
    int t1 = 0, t2 = 0;
    for (__typeof(n + 1) j = (i); j != (n + 1); j++) {
      t1 = t1 | a[j];
      t2 = t2 | b[j];
      ans = max(ans, t1 + t2);
    }
  }
  cout << ans << endl;
  return 0;
}
