#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  int b[n + 1];
  int k = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i == 1) k = a[i];
    if (i >= 2) {
      k = (k | a[i]);
    }
  }
  int t = 0;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (i == 1) t = b[i];
    if (i >= 2) {
      t = (t | b[i]);
    }
  }
  cout << k + t;
  return 0;
  return 0;
}
