#include <bits/stdc++.h>
using namespace std;
int main() {
  long long sum = 0;
  int n;
  scanf("%d", &n);
  int tmp = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    tmp |= x;
  }
  sum += tmp;
  tmp = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    tmp |= x;
  }
  sum += tmp;
  cout << sum;
  return 0;
}
