#include <bits/stdc++.h>
using namespace std;
int a, b, i, r, n, k, l, j, s;
int main() {
  cin >> n >> l;
  for (i = 2; i <= n; i++) {
    cin >> a;
    l = (l | a);
  }
  cin >> r;
  for (i = 2; i <= n; i++) {
    cin >> a;
    r = (r | a);
  }
  cout << l + r;
}
