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