#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k;
  int count, sum;
  int n, m, p, t;
  vector<int> v;
  int maxi, mini;
  int tc, ora, orb;
  string s, r;
  int lens, lenr;
  cin >> n;
  int a[n], b[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  maxi = INT_MIN;
  for (i = 0; i < n; i++) {
    ora = a[i];
    orb = b[i];
    maxi = max(maxi, ora + orb);
    for (j = i + 1; j < n; j++) {
      ora |= a[j];
      orb |= b[j];
      maxi = max(maxi, ora + orb);
    }
  }
  cout << maxi << endl;
  return 0;
}
