from bisect import* (n,),*e=[[*map(int,s.split())]for s in open(0)] p=[0] for r,R in sorted(e): i=bisect_right(p,r)-1 if 0<=i