#include <bits/stdc++.h>
using namespace std;
long long int func(long long int a[], long long int r) {
  long long int b = 0;
  for (long long int i = 0; i <= r; i++) b = b | a[i];
  return b;
}
int main() {
  long long int n, a[1002], b[1002];
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < n; i++) cin >> b[i];
  cout << func(a, n - 1) + func(b, n - 1) << endl;
  return 0;
}
