#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<long long> b(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    long long ba = a[i], bb = b[i];
    for (long long j = i + 1; j < n; j++) {
      mx = max(mx, ba + bb);
      ba = ba | a[j];
      bb = bb | b[j];
    }
    mx = max(mx, ba + bb);
  }
  cout << mx << endl;
  return 0;
}
