def search(n):

    idx = n

    while A[n-1] != n:

        n = A[n-1]

    A[idx-1] = n



    return n



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

A = [i for i in range(1, N+1)]

ans = 0



for i in range(M):

    X, Y, Z = list(map(int, input().split()))

    X_root, Y_root = search(X), search(Y)



    if X_root != Y_root:

        A[X_root-1] = Y_root

        ans += 1



print((N-ans))
import sys



input = sys.stdin.readline



def search(x, y):

    while root[x] != x: x = root[x]

    while root[y] != y: y = root[y]

    return x, y



def rebuild(x, y, r):

    while root[x] != r: x, root[x] = root[x], r

    while root[y] != r: y, root[y] = root[y], r

        

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



root = {i:i for i in range(1, N+1)}

size = {i:1 for i in range(1, N+1)}

ans = 0



for i in range(M):

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

    

    x_r, y_r = search(x, y)



    if x_r == y_r: continue

    

    root[y_r] = x_r

    size[x_r] += size[y_r]

    if size[x_r] > 10: rebuild(x, y, x_r)

    ans += 1



print((N-ans))
def search(n):
    idx = n
    while A[n - 1] != n:
        n = A[n - 1]
    A[idx - 1] = n
    return n


N, M = list(map(int, input().split()))
A = [i for i in range(1, N + 1)]
ans = 0
for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, Y_root = search(X), search(Y)
    if X_root != Y_root:
        A[X_root - 1] = Y_root
        ans += 1
print((N - ans))

import sys

input = sys.stdin.readline


def search(x, y):
    while root[x] != x:
        x = root[x]
    while root[y] != y:
        y = root[y]
    return x, y


def rebuild(x, y, r):
    while root[x] != r:
        x, root[x] = root[x], r
    while root[y] != r:
        y, root[y] = root[y], r


N, M = list(map(int, input().split()))
root = {i: i for i in range(1, N + 1)}
size = {i: 1 for i in range(1, N + 1)}
ans = 0
for i in range(M):
    x, y, z = list(map(int, input().split()))
    x_r, y_r = search(x, y)
    if x_r == y_r:
        continue
    root[y_r] = x_r
    size[x_r] += size[y_r]
    if size[x_r] > 10:
        rebuild(x, y, x_r)
    ans += 1
print((N - ans))

-def search(n): -    idx = n -    while A[n - 1] != n: -        n = A[n - 1] -    A[idx - 1] = n -    return n +import sys + +input = sys.stdin.readline + + +def search(x, y): +    while root[x] != x: +        x = root[x] +    while root[y] != y: +        y = root[y] +    return x, y + + +def rebuild(x, y, r): +    while root[x] != r: +        x, root[x] = root[x], r +    while root[y] != r: +        y, root[y] = root[y], r -A = [i for i in range(1, N + 1)] +root = {i: i for i in range(1, N + 1)} +size = {i: 1 for i in range(1, N + 1)} -    X, Y, Z = list(map(int, input().split())) -    X_root, Y_root = search(X), search(Y) -    if X_root != Y_root: -        A[X_root - 1] = Y_root -        ans += 1 +    x, y, z = list(map(int, input().split())) +    x_r, y_r = search(x, y) +    if x_r == y_r: +        continue +    root[y_r] = x_r +    size[x_r] += size[y_r] +    if size[x_r] > 10: +        rebuild(x, y, x_r) +    ans += 1