import bisect def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 ranges = [] for _ in range(N): L = int(data[idx]) R = int(data[idx+1]) ranges.append((L, R)) idx += 2 dp = [] for L, R in ranges: if not dp: x = L dp.append(x) else: m = dp[-1] x_candidate = m + 1 optimal_x = max(L, x_candidate) if optimal_x <= R: dp.append(optimal_x) else: x = L pos = bisect.bisect_left(dp, x) if pos < len(dp) and x < dp[pos]: dp[pos] = x elif pos == 0: dp[0] = x print(len(dp)) if __name__ == "__main__": main()