(출처 : https://en.wikipedia.org/wiki/File:Greedy-search-path-example.gif)
# input: 5 1 5 2 3 3 5 4 7 5 8
import sys sys.stdin=open("input.txt", "r") n = int(input()) a = [] for i in range(n): b = list(map(int, input().split())) a.append(b) a.sort(key=lambda x: (x[1], x[0])) end = 0 cnt = 0 for i in range(n): if end <= a[i][0]: end = a[i][1] cnt += 1 print('최대수 : {}'.format(cnt)) # 최대수 : 3