#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long mx = 0, k1 = 0, k2 = 0;
  vector<int> a, b;
  cin >> n;
  a.resize(n + 1);
  b.resize(n + 1);
  for (int k = 1; k <= n; k++) {
    cin >> a[k];
  }
  for (int k = 1; k <= n; k++) {
    cin >> b[k];
  }
  for (int k = 1; k <= n; k++) {
    for (int i = k; i <= n; i++) {
      k1 = k1 | a[i];
      k2 = k2 | b[i];
      mx = max(mx, k1 + k2);
    }
    k1 = 0;
    k2 = 0;
  }
  cout << mx;
  return 0;
}
