#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n + 1], b[n + 1];
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans1 |= a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    ans2 |= b[i];
  }
  int max = ans1 + ans2;
  cout << max;
  return 0;
}
