

n,m = list(map(int, input().split()))



def g(u,parent):

    if parent[u]!= u:

        parent[u] = g(parent[u], parent)

    return parent[u]

parent = {u:u for u in range(1, n+1)}

for _ in range(m):

    u,v = list(map(int, input().split()))

    pu,pv = g(u,parent), g(v,parent)

    if pu!= pv:

        parent[pu] = pv



ans = 0

for u in parent:

    if g(u,parent) == u:

        ans+=1

print(ans -1)


n,m = list(map(int, input().split()))



def g(u,parent):

    if parent[u]!= u:

        parent[u] = g(parent[u], parent)

    return parent[u]

parent = list(range(n+1))

for _ in range(m):

    u,v = list(map(int, input().split()))

    pu,pv = g(u,parent), g(v,parent)

    if pu!= pv:

        parent[pu] = pv



ans = 0

for u in range(1, n+1):

    if g(u,parent) == u:

        ans+=1

print(ans -1)
n, m = list(map(int, input().split()))


def g(u, parent):
    if parent[u] != u:
        parent[u] = g(parent[u], parent)
    return parent[u]


parent = {u: u for u in range(1, n + 1)}
for _ in range(m):
    u, v = list(map(int, input().split()))
    pu, pv = g(u, parent), g(v, parent)
    if pu != pv:
        parent[pu] = pv
ans = 0
for u in parent:
    if g(u, parent) == u:
        ans += 1
print(ans - 1)

n, m = list(map(int, input().split()))


def g(u, parent):
    if parent[u] != u:
        parent[u] = g(parent[u], parent)
    return parent[u]


parent = list(range(n + 1))
for _ in range(m):
    u, v = list(map(int, input().split()))
    pu, pv = g(u, parent), g(v, parent)
    if pu != pv:
        parent[pu] = pv
ans = 0
for u in range(1, n + 1):
    if g(u, parent) == u:
        ans += 1
print(ans - 1)

-parent = {u: u for u in range(1, n + 1)} +parent = list(range(n + 1)) -for u in parent: +for u in range(1, n + 1):