#include <bits/stdc++.h>
using namespace std;
int n, a[1001], b[1001];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int ra = a[i], rb = b[i];
    res = max(res, ra + rb);
    for (int j = i + 1; j <= n; j++) {
      ra |= a[j];
      rb |= b[j];
      res = max(res, ra + rb);
    }
  }
  cout << res << endl;
  return 0;
}
