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