#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[1005], b[1005], fa, fb;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  fa = a[1];
  fb = b[1];
  for (int i = 2; i <= n; i++) {
    fa |= a[i];
    fb |= b[i];
  }
  cout << fa + fb;
  return 0;
}
