#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
int main() {
  int n;
  cin >> n;
  long long ans1 = 0, ans2 = 0;
  long long a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans1 |= a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    ans2 |= b[i];
  }
  long long ans = ans1 + ans2;
  cout << ans;
}
