#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a[1010], b[1010], sum, amax = 0, bmax = 0, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    amax = (a[i] | amax);
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    bmax = (b[i] | bmax);
  }
  cout << amax + bmax << endl;
  return 0;
}
