#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000], b[1000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) scanf("%d", a + i);
  for (int i = 0; i < (int)(n); ++i) scanf("%d", b + i);
  int x = 0, y = 0;
  for (int i = 0; i < (int)(n); ++i) x |= a[i];
  for (int i = 0; i < (int)(n); ++i) y |= b[i];
  cout << (long long)x + y << endl;
  return 0;
}
