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