#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ai, bi, i, ora = 0, orb = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ai;
    ora |= ai;
  }
  for (i = 0; i < n; i++) {
    cin >> bi;
    orb |= bi;
  }
  cout << ora + orb << endl;
  return 0;
}
