read N
awk '{print $0,NR<='$N'?0:1}'\
	| sort -nk1\
	| awk '{a[NR,1]=$2; a[NR,2]=$3} END{
				cnt=0
				for(i=1;i<=NR;i++) {
					if(a[i,2]==1) {
						max=-1
						ind=0
						for(j=1;j<i;j++){
							if(a[j,1]!=""&&a[j,2]==0&&a[j,1]<a[i,1]&&max<a[j,1]){
								max=a[j,1]
								ind=j
							}
						}
						if(ind!=0){
							cnt++
							a[ind,1]=a[ind,2]=""
						}
					}
				}
				print cnt
			}'