#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n;
int main() {
  int aa = 0, bb = 0;
  int help;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> help;
    aa |= help;
  }
  for (int i = 0; i < n; ++i) {
    cin >> help;
    bb |= help;
  }
  cout << aa + bb;
}
