#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int a[maxn], b[maxn];
int main() {
  int n, m1 = 0, m2 = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    m1 |= a[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    m2 |= b[i];
  }
  printf("%d\n", m1 + m2);
}
