import bisect n = int(input()) intervals = [tuple(map(int, input().split())) for _ in range(n)] tails = [] for L, R in intervals: idx = bisect.bisect_left(tails, R) j = idx - 1 if j >= 0: current = tails[j] + 1 else: current = L x = max(current, L) if x > R: continue if j + 1 < len(tails): if x < tails[j+1]: tails[j+1] = x else: tails.append(x) print(len(tails))