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