#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, k, cur1, cur2;
long long sum = 0;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &k);
    cur1 = cur1 | k;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &k);
    cur2 = cur2 | k;
  }
  sum = cur1 + cur2 * 1LL;
  cout << sum << endl;
  return 0;
}
