nums = [] for _ in range(n): tmp = list(map(int,input().split())) nums.append(tmp)
nums = sorted(nums,key=lambda x:x[1])
ans = 2 x= nums[0][-1] #最大的元素 y = nums[0][-1]-1#次大的元素
for l in nums[1:]: if l[0]<=x<=l[-1] and l[0]<=y<=l[-1]: ans += 0 elif l[0]<=x<=l[-1] or l[0]<=y<=l[-1]: y = x x = l[-1] ans+=1 else: ans+=2 x = l[-1] y = l[-1] - 1