#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N], b[N];
int n, l, r;
int F(int *x, int l, int r) {
  int sum = 0;
  for (int i = l; i <= r; i++) sum = sum | x[i];
  return sum;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int ans = F(a, 0, n) + F(b, 0, n);
  cout << ans;
  return 0;
}
