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