#include <bits/stdc++.h>
using namespace std;
int main() {
  long long 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];
  long long maxx = 0, ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    ans1 = 0;
    ans2 = 0;
    for (int j = i; j < n; j++) {
      ans1 |= a[j];
      ans2 |= b[j];
      maxx = max(maxx, (ans1 + ans2));
    }
  }
  printf("%I64d", maxx);
  return 0;
}
