link
int getint(){
int res=0;
char c=getchar();
while(!(c>='0' && c<='9')) c=getchar();
while(c>='0' && c<='9'){
res=res*10+(c-'0');
c=getchar();
}
return res;
}
int helper(vector<int>& num1, vector<int>& num2){
int len1=num1.size();
int len2=num2.size();
int halflen=(len1+len2+1)/2;
int left=0;
int right=len1;
while(left<=right){
int mid=left+(right-left)/2;
int n1=mid;
int n2=halflen-mid;
int leftmax1=(n1==0)?INT_MIN:num1[n1-1];
int rightmin1=(n1==len1)?INT_MAX:num1[n1];
int leftmax2=(n2==0)?INT_MIN:num2[n2-1];
int rightmin2=(n2==len2)?INT_MAX:num2[n2];
if(leftmax1<=rightmin2 && leftmax2<=rightmin1){
return max(leftmax1,leftmax2);
}
if(leftmax1>rightmin2){
right=mid-1;
}else{
left=mid+1;
}
}
return -1;
}
int main(){
int n1=getint();
vector<int> num1(n1);
for(int i=0;i<n1;i++){
num1[i]=getint();
}
int n2=getint();
vector<int> num2(n2);
for(int i=0;i<n2;i++){
num2[i]=getint();
}
int res=0;
if(n1<=n2){
res=helper(num1,num2);
}else{
res=helper(num2,num1);
}
printf("%d", res);
return 0;
}