#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 2;
long long a[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long maxv = 0;
  for (int i = 0; i < n; i++) {
    long long acc1 = 0, acc2 = 0;
    for (int j = i; j < n; j++) {
      acc1 |= a[j];
      acc2 |= b[j];
      maxv = max(acc1 + acc2, maxv);
    }
  }
  cout << maxv << endl;
  return 0;
}
