#include <bits/stdc++.h>
using namespace std;
long long ara1[10000], ara2[10000];
long long maxx;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &ara1[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &ara2[i]);
  }
  for (int i = 0; i < n; i++) {
    long long aa = ara1[i], bb = ara2[i];
    maxx = max(maxx, aa + bb);
    for (int j = i + 1; j < n; j++) {
      aa |= ara1[j];
      bb |= ara2[j];
      maxx = max(maxx, aa + bb);
    }
  }
  printf("%lld\n", maxx);
  return 0;
}
