#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n], b[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];
  long long int left = 0, ryt = 0;
  for (long long int i = 0; i < 32; ++i) {
    for (long long int j = 0; j < n; ++j) {
      if (a[j] & (1 << i)) {
        left += pow(2, i);
        break;
      }
    }
  }
  for (long long int i = 0; i < 32; ++i) {
    for (long long int j = 0; j < n; ++j) {
      if (b[j] & (1 << i)) {
        ryt += pow(2, i);
        break;
      }
    }
  }
  long long int ans = left + ryt;
  cout << ans << "\n";
  return 0;
}
