#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  if (n == 1) {
    cout << a[0] + b[0];
    return 0;
  }
  int m = a[0] + b[0];
  for (int i = 1; i < n; i++) {
    int u = a[i], y = b[i];
    m = max(m, u + y);
    for (int j = i - 1; j >= 0; j--) {
      u = u | a[j];
      y = y | b[j];
      m = max(m, u + y);
    }
  }
  cout << m;
}
