#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[1000], b[1000];
  int o1 = 0, o2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], o2 |= a[i];
  for (int i = 0; i < n; i++) cin >> b[i], o1 |= b[i];
  cout << o1 + o2;
  return 0;
}
