import sys

import numpy as np

sys.setrecursionlimit(10 ** 7)



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M = lr()



# Aでxの根を求める

def find(A, x):

    p = A[x]

    if p == x:

        return x

    a = find(A, p)

    A[x] = a

    return a



# Aでxとyの属する集合の併合

def union(A, x, y):

    if find(A, x) > find(A, y):

        bx, by = find(A, y), find(A, x)

    else:

        bx, by = find(A, x), find(A, y)

    # 根をbx(値の小さい方)に統一 

    A[by] = bx



V = [i for i in range(N)]

for i in range(M):

    x, y, z = lr()

    if find(V, x-1) != find(V, y-1):

        union(V, x-1, y-1)



answer = [find(V, x) for x in set(V)]

print((len(set(answer))))

# 36

# coding: utf-8

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



# Aでxの根を求める

def find(A,x):

    p = A[x]

    if p == x: return x

    a = find(A,p)

    A[x] = a

    return a

# Aでxとyの属する集合の併合

def union(A, x, y):

    if find(A,x) > find(A,y):

        bx, by = find(A,y), find(A,x)

    else:

        bx, by = find(A,x), find(A,y)

    A[by] = bx # 根をbxに統一



N, M = lr()

V = [x for x in range(N+1)]

for _ in range(M):

    x, y, z = lr()

    if find(V, x) != find(V, y):

        union(V, x, y)



V = [find(V, x) for x in V]

s = set(V[1:])

answer = len(s)

print(answer)

# 55

import sys
import numpy as np

sys.setrecursionlimit(10**7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
# Aでxの根を求める
def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a


# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A, x) > find(A, y):
        bx, by = find(A, y), find(A, x)
    else:
        bx, by = find(A, x), find(A, y)
    # 根をbx(値の小さい方)に統一
    A[by] = bx


V = [i for i in range(N)]
for i in range(M):
    x, y, z = lr()
    if find(V, x - 1) != find(V, y - 1):
        union(V, x - 1, y - 1)
answer = [find(V, x) for x in set(V)]
print((len(set(answer))))
# 36

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# Aでxの根を求める
def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a


# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A, x) > find(A, y):
        bx, by = find(A, y), find(A, x)
    else:
        bx, by = find(A, x), find(A, y)
    A[by] = bx  # 根をbxに統一


N, M = lr()
V = [x for x in range(N + 1)]
for _ in range(M):
    x, y, z = lr()
    if find(V, x) != find(V, y):
        union(V, x, y)
V = [find(V, x) for x in V]
s = set(V[1:])
answer = len(s)
print(answer)
# 55

+# coding: utf-8 -import numpy as np -sys.setrecursionlimit(10**7) -N, M = lr() -    # 根をbx(値の小さい方)に統一 -    A[by] = bx +    A[by] = bx  # 根をbxに統一 -V = [i for i in range(N)] -for i in range(M): +N, M = lr() +V = [x for x in range(N + 1)] +for _ in range(M): -    if find(V, x - 1) != find(V, y - 1): -        union(V, x - 1, y - 1) -answer = [find(V, x) for x in set(V)] -print((len(set(answer)))) -# 36 +    if find(V, x) != find(V, y): +        union(V, x, y) +V = [find(V, x) for x in V] +s = set(V[1:]) +answer = len(s) +print(answer) +# 55