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