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