break_offs = set()

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

for i in range(M):

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

    if a > b:

        a, b = b, a

    break_offs.add((a, b))



covered = []

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

for a, b in break_offs:

    found = False

    for area in covered:

        if not (area[0] >= b or area[1] <= a):

            covered.remove(area)

            covered.append((max(area[0], a), min(area[1], b)))

            found = True

            break



    if not found:

        covered.append((a, b))





answer = len(covered)

print(answer)
break_offs = set()

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

for i in range(M):

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

    if a > b:

        a, b = b, a

    break_offs.add((a, b))



last_bridge = 0

count = 0

for a, b in sorted(list(break_offs), key=lambda x:x[1]):

    if last_bridge <= a:

        last_bridge = b

        count += 1



print(count)
break_offs = set()
N, M = list(map(int, input().split()))
for i in range(M):
    a, b = list(map(int, input().split()))
    if a > b:
        a, b = b, a
    break_offs.add((a, b))
covered = []
break_offs = sorted(list(break_offs), key=lambda x: x[1])
for a, b in break_offs:
    found = False
    for area in covered:
        if not (area[0] >= b or area[1] <= a):
            covered.remove(area)
            covered.append((max(area[0], a), min(area[1], b)))
            found = True
            break
    if not found:
        covered.append((a, b))
answer = len(covered)
print(answer)

break_offs = set()
N, M = list(map(int, input().split()))
for i in range(M):
    a, b = list(map(int, input().split()))
    if a > b:
        a, b = b, a
    break_offs.add((a, b))
last_bridge = 0
count = 0
for a, b in sorted(list(break_offs), key=lambda x: x[1]):
    if last_bridge <= a:
        last_bridge = b
        count += 1
print(count)

-covered = [] -break_offs = sorted(list(break_offs), key=lambda x: x[1]) -for a, b in break_offs: -    found = False -    for area in covered: -        if not (area[0] >= b or area[1] <= a): -            covered.remove(area) -            covered.append((max(area[0], a), min(area[1], b))) -            found = True -            break -    if not found: -        covered.append((a, b)) -answer = len(covered) -print(answer) +last_bridge = 0 +count = 0 +for a, b in sorted(list(break_offs), key=lambda x: x[1]): +    if last_bridge <= a: +        last_bridge = b +        count += 1 +print(count)