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

AB = []

for _ in range(M):

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

    AB.append((a, b))

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

cnt = 1

x = AB[0][1]

for a, b in AB:

    if a <= x - 1 <= b and a <= x <= b:

        continue

    else:

        cnt += 1

        x = b

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

AB = []

for _ in range(M):

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

    AB.append((a, b))



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

# print(AB)

base = AB[0][1]

ans = 1

for ab in AB[1:]:

    if ab[0] < base <= ab[1]:

        continue

    else:

        ans += 1

        base = ab[1]

print(ans)
N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    AB.append((a, b))
AB.sort(key=lambda x: x[1])
cnt = 1
x = AB[0][1]
for a, b in AB:
    if a <= x - 1 <= b and a <= x <= b:
        continue
    else:
        cnt += 1
        x = b
print(cnt)

N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    AB.append((a, b))
AB.sort(key=lambda x: x[1])
# print(AB)
base = AB[0][1]
ans = 1
for ab in AB[1:]:
    if ab[0] < base <= ab[1]:
        continue
    else:
        ans += 1
        base = ab[1]
print(ans)

-cnt = 1 -x = AB[0][1] -for a, b in AB: -    if a <= x - 1 <= b and a <= x <= b: +# print(AB) +base = AB[0][1] +ans = 1 +for ab in AB[1:]: +    if ab[0] < base <= ab[1]: -        cnt += 1 -        x = b -print(cnt) +        ans += 1 +        base = ab[1] +print(ans)