#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum[2] = {0};
  int long long cop;
  vector<vector<long long int> > arr(2);
  scanf("%d", &n);
  arr[0].resize(n);
  arr[1].resize(n);
  for (int i = 0; i < 2; i++) {
    scanf("%d", &arr[i][0]);
    sum[i] = sum[i] | arr[i][0];
    for (int j = 1; j < n; j++) {
      scanf("%d", &arr[i][j]);
      sum[i] = sum[i] | arr[i][j];
    }
  }
  printf("%d\n", sum[0] + sum[1]);
  return 0;
}
