#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  cin >> n;
  bool Boola[32], Boolb[32];
  long p[31], a[n], b[n];
  long long int ans;
  p[0] = 1;
  Boola[0] = false;
  Boolb[0] = false;
  for (i = 1; i < 31; i++) {
    Boola[i] = false;
    Boolb[i] = false;
    p[i] = p[i - 1] * 2;
  }
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (i = 30; i >= 0; i--) {
    for (j = 0; j < n; j++) {
      if (p[i] <= a[j]) {
        a[j] -= p[i];
        Boola[i] = true;
      }
      if (p[i] <= b[j]) {
        b[j] -= p[i];
        Boolb[i] = true;
      }
    }
  }
  ans = 0;
  for (i = 0; i < 31; i++) {
    if (Boolb[i]) ans += p[i];
    if (Boola[i]) ans += p[i];
  }
  cout << ans;
  return 0;
}
