#include <bits/stdc++.h>
using namespace std;
long long a[10010];
long long b[10010];
int main() {
  int i, j, n;
  while (scanf("%d", &n) != EOF) {
    long long value1 = 0, value2 = 0;
    for (i = 1; i <= n; i++) {
      scanf("%I64d", &a[i]);
      value1 = value1 | a[i];
    }
    for (i = 1; i <= n; i++) {
      scanf("%I64d", &b[i]);
      value2 = value2 | b[i];
    }
    printf("%I64d\n", value1 + value2);
  }
  return 0;
}
