#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long ans = 0, s1 = 0, s2 = 0;
  int n;
  cin >> n;
  vector<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];
  for (int i = 0; i < n; ++i) {
    s1 = 0;
    s2 = 0;
    for (int j = i; j < n; ++j) {
      s1 |= a[j];
      s2 |= b[j];
      ans = max(ans, s1 + s2);
    }
  }
  cout << ans;
  return 0;
}
