#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  while (cin >> n) {
    int ar[1005], b[1005];
    for (int i = 0; i < n; i++) cin >> ar[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    long res = 0, mx = 0, r1 = 0, r2 = 0;
    for (int i = 0; i < n; i++) {
      res = 0;
      r1 = 0, r2 = 0;
      for (int j = i; j < n; j++) {
        r1 = (r1 | ar[j]);
        r2 = (r2 | b[j]);
        mx = max(mx, r1 + r2);
      }
    }
    cout << mx << endl;
  }
}
