#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long long infl = 9e18;
int main() {
  ios_base::sync_with_stdio(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];
  int ans = a[0] + b[0];
  for (int i = 0; i < n; i++) {
    int ax = a[i], bx = b[i];
    for (int j = i + 1; j < n; j++) {
      ax |= a[j];
      bx |= b[j];
      ans = max(ans, ax + bx);
    }
  }
  cout << ans;
}
