#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, m, k, temp, suma = 0, sumb = 0;
  cin >> n;
  unsigned long long int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a;
    suma = suma | a;
  }
  for (int i = 0; i < n; i++) {
    cin >> b;
    sumb = sumb | b;
  }
  cout << suma + sumb;
  return 0;
}
