#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, m, cnt = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  for (i = 0; i < n; i++) {
    int ca = 0, cb = 0;
    for (j = i; j < n; j++) {
      ca |= a[j];
      cb |= b[j];
      cnt = max(cnt, ca + cb);
    }
  }
  cout << cnt << endl;
  return 0;
}
