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