#include<bits/stdc++.h>
using namespace std;
int maxi = 0;
bool set2;
int N, A[200005], B[200005];
void Set2(){
  for(int i = 1; i <= N; i++)
    maxi = max(maxi, B[i]);
  printf("%d\n", maxi);
  exit(0);
}
int main(){
  cin >> N;
  for(int i = 1; i <= N; i++){
    cin >> A[i];
    if(A[i] != 1)set2 = true;
  }
  for(int i = 1; i <= N; i++)cin >> B[i];
  if(!set2)Set2();

return 0;
}