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

A = []

for i in range(M):

  a, b = list(map(int, input().split()))

  A.append([a - 1, b - 1])

A = sorted(A, key=lambda a: a[0])

cut = 1

b_min = N

for a in A:

  if a[0] >= b_min:

    cut += 1

    b_min = N

  b_min = min(b_min, a[1])

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

I = [N + 1 for i in range(N)]

for i in range(M):

  a, b = list(map(int, input().split()))

  I[a - 1] = min(I[a - 1], b - 1)

cut = 0

for i in range(N - 1):

  if I[i] == i + 1:

    cut += 1

  else:

    I[i + 1] = min(I[i + 1], I[i])

print(cut)
N, M = list(map(int, input().split()))
A = []
for i in range(M):
    a, b = list(map(int, input().split()))
    A.append([a - 1, b - 1])
A = sorted(A, key=lambda a: a[0])
cut = 1
b_min = N
for a in A:
    if a[0] >= b_min:
        cut += 1
        b_min = N
    b_min = min(b_min, a[1])
print(cut)

N, M = list(map(int, input().split()))
I = [N + 1 for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    I[a - 1] = min(I[a - 1], b - 1)
cut = 0
for i in range(N - 1):
    if I[i] == i + 1:
        cut += 1
    else:
        I[i + 1] = min(I[i + 1], I[i])
print(cut)

-A = [] +I = [N + 1 for i in range(N)] -    A.append([a - 1, b - 1]) -A = sorted(A, key=lambda a: a[0]) -cut = 1 -b_min = N -for a in A: -    if a[0] >= b_min: +    I[a - 1] = min(I[a - 1], b - 1) +cut = 0 +for i in range(N - 1): +    if I[i] == i + 1: -        b_min = N -    b_min = min(b_min, a[1]) +    else: +        I[i + 1] = min(I[i + 1], I[i])