#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline P smin(P &a, Q b) {
  if (b < a) a = b;
  return a;
}
template <class P, class Q>
inline P smax(P &a, Q b) {
  if (a < b) a = b;
  return a;
}
const int N = 1005;
int a[N], b[N];
int read() {
  int x;
  cin >> x;
  return x;
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n = read();
  for (int i = 0, _n = (int)(n); i < _n; i++) cin >> a[i];
  for (int i = 0, _n = (int)(n); i < _n; i++) cin >> b[i];
  long long x = 0, y = 0;
  for (int l = 0, _n = (int)(n); l < _n; l++) {
    x |= a[l];
    y |= b[l];
  }
  cout << x + y;
}
