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