from sys import stdin
m=int(stdin.readline())
data=[]
for i in range(m):
data.append(list(map(int,stdin.readline().split())))
data.sort(key=lambda x:x[1])
#print(data)
k=data[-1][-1]
diff=[0]*(k+1)
have=diff.copy()
for i in data:
diff[i[0]]+=1
diff[i[1]]-=1
ans=0
diff.insert(0,0)
have.append(0)
for i in range(1,len(have)):
have[i]=have[i-1]+diff[i]
if have[i]>0:
ans+=1
print(ans)