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

E = []

for i in range(M):

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

    a, b = a-1, b-1

    E.append([a, b])



E.sort()

l, r = 0, float('inf')

ans = 0

for a, b in E:

    if b <= l or a >= r:

        ans += 1

        l, r = a, b

    else:

        l = max(a, l)

        r = min(b, r)



print((ans + 1))

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

E = []

for i in range(M):

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

    a, b = a - 1, b - 1

    E.append([a, b])



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



r = 0

ans = 0

for a, b in E:

    if a >= r:

        ans += 1

        r = b



print(ans)

N, M = list(map(int, input().split()))
E = []
for i in range(M):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    E.append([a, b])
E.sort()
l, r = 0, float("inf")
ans = 0
for a, b in E:
    if b <= l or a >= r:
        ans += 1
        l, r = a, b
    else:
        l = max(a, l)
        r = min(b, r)
print((ans + 1))

N, M = list(map(int, input().split()))
E = []
for i in range(M):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    E.append([a, b])
E.sort(key=lambda x: x[1])
r = 0
ans = 0
for a, b in E:
    if a >= r:
        ans += 1
        r = b
print(ans)

-E.sort() -l, r = 0, float("inf") +E.sort(key=lambda x: x[1]) +r = 0 -    if b <= l or a >= r: +    if a >= r: -        l, r = a, b -    else: -        l = max(a, l) -        r = min(b, r) -print((ans + 1)) +        r = b +print(ans)