#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, nr, a = 0, b = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> nr;
    a |= nr;
  }
  for (int j = 0; j < n; j++) {
    cin >> nr;
    b |= nr;
  }
  cout << a + b << endl;
  return 0;
}
