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