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