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