#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
long long n, m, ans = 0, ans2 = 0, a[1010], b[1010];
string s[1005], s2[1010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    bitset<40> bs(a[i]);
    string tmp;
    for (int j = 0; j < 40; j++) bs[j] == 1 ? tmp += '1' : tmp += '0';
    s[i] = tmp;
  }
  for (int i = 0; i < n; i++) {
    bitset<40> bs(b[i]);
    string tmp;
    for (int j = 0; j < 40; j++) bs[j] == 1 ? tmp += '1' : tmp += '0';
    s2[i] = tmp;
  }
  for (int i = 0; i < 40; i++) {
    bool ok = 0;
    for (int j = 0; j < n; j++)
      if (s[j][i] == '1') ok = 1;
    if (ok) ans += (long long)pow(2, i);
  }
  for (int i = 0; i < 40; i++) {
    bool ok = 0;
    for (int j = 0; j < n; j++)
      if (s2[j][i] == '1') ok = 1;
    if (ok) ans2 += (long long)pow(2, i);
  }
  cout << ans + ans2;
  return 0;
}
