#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[10000], b[10000], n, max0 = 0, max1 = 0, c = 2, d = 12;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c;
    max0 = max0 | c;
  }
  for (int i = 0; i < n; i++) {
    cin >> c;
    max1 = max1 | c;
  }
  cout << max0 + max1;
}
