#include <bits/stdc++.h>
using namespace std;
int a[1016], b[1016];
int main() {
  int N, ma = 0, mb = 0;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int j = 0; j < N; j++) cin >> b[j];
  for (int i = 0; i < N; i++) ma |= a[i];
  for (int i = 0; i < N; i++) mb |= b[i];
  cout << ma + mb;
  return 0;
}
