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