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

G=[list() for i in range(N)]

for i in range(M):

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

    a-=1

    b-=1

    G[a].append(b)

    G[b].append(a)

ans=0

index=-1

for i in range(1,N):

    for p in G[i]:

        if index<p<i:

            ans+=1

            index=i-1

import time

time.sleep(1.54)

print(ans)

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

G=[list() for i in range(N)]

for i in range(M):

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

    a-=1

    b-=1

    G[a].append(b)

    G[b].append(a)

ans=0

index=-1

for i in range(1,N):

    for p in G[i]:

        if index<p<i:

            ans+=1

            index=i-1

            break

print(ans)

N, M = list(map(int, input().split()))
G = [list() for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
ans = 0
index = -1
for i in range(1, N):
    for p in G[i]:
        if index < p < i:
            ans += 1
            index = i - 1
import time

time.sleep(1.54)
print(ans)

N, M = list(map(int, input().split()))
G = [list() for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
ans = 0
index = -1
for i in range(1, N):
    for p in G[i]:
        if index < p < i:
            ans += 1
            index = i - 1
            break
print(ans)

-import time - -time.sleep(1.54) +            break