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

B = []

for m in range(M):

    B.append(list(map(int, input().split())))

B = sorted(B, key=lambda x: x[1])



check = [B[0][1]-1]



for a, b in B:

    if a <= check[-1]:

        continue

    check.append(b-1)

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

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

B.sort()

r = 0

res = 0

for a, b in B:

    if a >= r:

        res += 1

        r = b

    else:

        r = min(r, b)

print(res)

N, M = list(map(int, input().split()))
B = []
for m in range(M):
    B.append(list(map(int, input().split())))
B = sorted(B, key=lambda x: x[1])
check = [B[0][1] - 1]
for a, b in B:
    if a <= check[-1]:
        continue
    check.append(b - 1)
print((len(check)))

N, M = list(map(int, input().split()))
B = [tuple(map(int, input().split())) for _ in range(M)]
B.sort()
r = 0
res = 0
for a, b in B:
    if a >= r:
        res += 1
        r = b
    else:
        r = min(r, b)
print(res)

-B = [] -for m in range(M): -    B.append(list(map(int, input().split()))) -B = sorted(B, key=lambda x: x[1]) -check = [B[0][1] - 1] +B = [tuple(map(int, input().split())) for _ in range(M)] +B.sort() +r = 0 +res = 0 -    if a <= check[-1]: -        continue -    check.append(b - 1) -print((len(check))) +    if a >= r: +        res += 1 +        r = b +    else: +        r = min(r, b) +print(res)