#include <bits/stdc++.h>
using namespace std;
const int N = 1234;
int a[N], b[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", b + i);
  }
  int ans = 0;
  int s = 0;
  for (int i = 0; i < n; i++) {
    s |= a[i];
  }
  ans += s;
  s = 0;
  for (int i = 0; i < n; i++) {
    s |= b[i];
  }
  ans += s;
  cout << ans << '\n';
  return 0;
}
