#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, *a, *b, z, c, d, v, u;
  a = (long long*)malloc(sizeof(long long) * 1000000);
  b = (long long*)malloc(sizeof(long long) * 1000000);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  z = 0;
  for (i = 0; i < n; i++) {
    d = a[i];
    c = b[i];
    for (j = i; j < n; j++) {
      d = d | a[j];
      c = c | b[j];
      if (d + c > z) {
        z = d + c;
        v = i;
        u = j;
      }
    }
  }
  free(a);
  free(b);
  cout << z << "\n";
  return 0;
}
