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