#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  int b[n + 1];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  int t[n + 1][n + 1];
  int mx = -1;
  for (int i = 0; i < n; i++) {
    int t1 = a[i];
    int t2 = b[i];
    for (int j = i; j < n; j++) {
      t1 = (t1 | a[j]);
      t2 = (t2 | b[j]);
      t[i][j] = t1 + t2;
      mx = max(mx, t[i][j]);
    }
  }
  cout << mx;
  return 0;
}
