#include <bits/stdc++.h>
using namespace std;
int main() {
  int timer;
  timer = 1;
  while (timer--) {
    long long n, i, j, a = 0, b = 0;
    cin >> n;
    long long dta[n];
    for (i = 0; i < n; ++i) {
      cin >> j;
      a = a | j;
    }
    for (i = 0; i < n; ++i) {
      cin >> j;
      b = b | j;
    }
    cout << (a + b) << "\n";
  }
}
