#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, i, a, b;
int A[N], B[N];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", A + i);
    a |= A[i];
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", B + i);
    b |= B[i];
  }
  cout << a + b << endl;
}
