#include <bits/stdc++.h>
using namespace std;
inline void init() {
  cin.tie(0);
  cout.tie(0);
  std::ios::sync_with_stdio(false);
}
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int main() {
  init();
  int n, x = 0, y = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    x |= t;
  }
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    y |= t;
  }
  cout << x + y << "\n";
  return 0;
}
