# union-findで行けそう。



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

par = [-1] * (n + 1)





def find(a):

    if par[a] < 0:

        return a

    else:

        par[a] = find(par[a])

        return par[a]





def unite(a, b):

    a = find(a)

    b = find(b)

    if a == b:

        return False

    else:

        if par[a] < par[b]:

            a, b = b, a

        par[a] += par[b]

        par[b] = a

        return True





for i in range(m):

    x, y, z = list(map(int, input().split()))

    unite(x, y)

cnt = 0

for i in range(n):

    if par[i + 1] < 0:

        cnt += 1

print(cnt)

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

#union-find

par=[-1]*(n+1)

def find(x):

    if par[x]<0:

        return x

    else:

        par[x]=find(par[x])

        return par[x]

def size(x):

    oya=find(x)

    return -par[oya]

def unite(x,y):

    if find(x)==find(y):

        return False

    else:

        if size(y)>size(x):

            y,x=x,y  #xを大きい親にしておくか

        oya_x=find(x)

        oya_y=find(y)

        par[oya_x]-=size(oya_y)  #xの大きさをyにしておく

        par[oya_y]=oya_x  #yの親をxに

        return True



def is_same(x,y):

    return find(x)==find(y)

for _ in range(m):

    x,y,z=list(map(int,input().split()))

    unite(x,y)

ans_set=set()

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

    ans_set.add(find(i))

print((len(ans_set)))
# union-findで行けそう。
n, m = list(map(int, input().split()))
par = [-1] * (n + 1)


def find(a):
    if par[a] < 0:
        return a
    else:
        par[a] = find(par[a])
        return par[a]


def unite(a, b):
    a = find(a)
    b = find(b)
    if a == b:
        return False
    else:
        if par[a] < par[b]:
            a, b = b, a
        par[a] += par[b]
        par[b] = a
        return True


for i in range(m):
    x, y, z = list(map(int, input().split()))
    unite(x, y)
cnt = 0
for i in range(n):
    if par[i + 1] < 0:
        cnt += 1
print(cnt)

n, m = list(map(int, input().split()))
# union-find
par = [-1] * (n + 1)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def size(x):
    oya = find(x)
    return -par[oya]


def unite(x, y):
    if find(x) == find(y):
        return False
    else:
        if size(y) > size(x):
            y, x = x, y  # xを大きい親にしておくか
        oya_x = find(x)
        oya_y = find(y)
        par[oya_x] -= size(oya_y)  # xの大きさをyにしておく
        par[oya_y] = oya_x  # yの親をxに
        return True


def is_same(x, y):
    return find(x) == find(y)


for _ in range(m):
    x, y, z = list(map(int, input().split()))
    unite(x, y)
ans_set = set()
for i in range(1, n + 1):
    ans_set.add(find(i))
print((len(ans_set)))

-# union-findで行けそう。 +# union-find -def find(a): -    if par[a] < 0: -        return a +def find(x): +    if par[x] < 0: +        return x -        par[a] = find(par[a]) -        return par[a] +        par[x] = find(par[x]) +        return par[x] -def unite(a, b): -    a = find(a) -    b = find(b) -    if a == b: +def size(x): +    oya = find(x) +    return -par[oya] + + +def unite(x, y): +    if find(x) == find(y): -        if par[a] < par[b]: -            a, b = b, a -        par[a] += par[b] -        par[b] = a +        if size(y) > size(x): +            y, x = x, y  # xを大きい親にしておくか +        oya_x = find(x) +        oya_y = find(y) +        par[oya_x] -= size(oya_y)  # xの大きさをyにしておく +        par[oya_y] = oya_x  # yの親をxに -for i in range(m): +def is_same(x, y): +    return find(x) == find(y) + + +for _ in range(m): -cnt = 0 -for i in range(n): -    if par[i + 1] < 0: -        cnt += 1 -print(cnt) +ans_set = set() +for i in range(1, n + 1): +    ans_set.add(find(i)) +print((len(ans_set)))