#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  int oringA, oringB, maxi = 0;
  for (int i = 0; i < n; ++i) {
    oringA = a[i], oringB = b[i];
    for (int j = i; j < n; ++j) {
      oringA = oringA | a[j];
      oringB = oringB | b[j];
      if (oringA + oringB > maxi) maxi = oringA + oringB;
    }
  }
  cout << maxi << "\n";
  return 0;
}
