N, M = list(map(int, input().split()))



AB = [list(map(int, input().split())) for _ in range(M)]



AB.sort(key = lambda x: x[0])



MAX = 10 ** 9



count = 1

min_ = MAX

for a, b in AB:

    if a < min_:

        min_ = min(min_, b)

    else:

        count += 1

        min_ = b



print (count)

N, M = list(map(int, input().split()))



AB = [tuple(map(int, input().split())) for _ in range(M)]

AB.sort(key = lambda x: x[0])



count = 1

B = 10 ** 9

for a, b in AB:

    if a < B:

        B = min(B, b)

    else:

        count += 1

        B = b



print (count)

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
AB.sort(key=lambda x: x[0])
MAX = 10**9
count = 1
min_ = MAX
for a, b in AB:
    if a < min_:
        min_ = min(min_, b)
    else:
        count += 1
        min_ = b
print(count)

N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(M)]
AB.sort(key=lambda x: x[0])
count = 1
B = 10**9
for a, b in AB:
    if a < B:
        B = min(B, b)
    else:
        count += 1
        B = b
print(count)

-AB = [list(map(int, input().split())) for _ in range(M)] +AB = [tuple(map(int, input().split())) for _ in range(M)] -MAX = 10**9 -min_ = MAX +B = 10**9 -    if a < min_: -        min_ = min(min_, b) +    if a < B: +        B = min(B, b) -        min_ = b +        B = b