#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 7;
long long mas[maxn] = {0};
long long mas1[maxn] = {0};
int main() {
  int n;
  int l = 1;
  long long maxi = -1e9;
  int r;
  cin >> n;
  r = n;
  for (int i = 1; i <= n; i++) {
    cin >> mas[i];
    mas[i] |= mas[i - 1];
    continue;
  }
  for (int i = 1; i <= n; i++) {
    cin >> mas1[i];
    mas1[i] |= mas1[i - 1];
    continue;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      maxi = max(maxi, (mas[i] | mas[i - 1]) + (mas1[i] | mas1[i - 1]));
  cout << maxi << endl;
  return 0;
}
