import bisect n = int(input()) intervals = [tuple(map(int, input().split())) for _ in range(n)] tails = [] for L, R in intervals: if not tails: tails.append(L) continue # Binary search for the largest j where max(tails[j] + 1, L) <= R low = 0 high = len(tails) - 1 result = -1 while low <= high: mid = (low + high) // 2 x_candidate = max(tails[mid] + 1, L) if x_candidate <= R: result = mid low = mid + 1 else: high = mid - 1 if result != -1: x = max(tails[result] + 1, L) if result + 1 == len(tails): tails.append(x) else: if x < tails[result + 1]: tails[result + 1] = x else: if L < tails[0]: tails[0] = L print(len(tails))