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