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