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