import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())
paths = [[] for _ in range(N)]

for _ in range(M):
    a, b, z = map(int, input().split())
    paths[a-1].append(b-1)
    paths[b-1].append(a-1)

visited = [False] * N

def dfs(node, prev):
    if visited[node]:
        return
    visited[node] = True
    for n in paths[node]:
        if n != prev:
            dfs(n, node)
count = 0
for i in range(N):
    if visited[i] == False:
        count += 1
        dfs(i,-1)

print(count) import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] paths = [[] for _ in range(N)] paths [[] for _ in range(N)] for _ in range(M):
    a, b, z = map(int, input().split())
    paths[a-1].append(b-1)
    paths[b-1].append(a-1) _ range(M) range M a, b, z = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b z paths[a-1].append(b-1) [a-1].append [a-1] paths a-1 a 1 append b-1 b 1 paths[b-1].append(a-1) [b-1].append [b-1] paths b-1 b 1 append a-1 a 1 visited = [False] * N visited [False] * N [False] False N def dfs(node, prev):
    if visited[node]:
        return
    visited[node] = True
    for n in paths[node]:
        if n != prev:
            dfs(n, node) dfs if visited[node]:
        return
     visited[node] visited node return visited[node] = True visited[node] visited node True for n in paths[node]:
        if n != prev:
            dfs(n, node) n paths[node] paths node if n != prev:
            dfs(n, node) n != prev n prev dfs(n, node) dfs n node node node prev prev count = 0 count 0 for i in range(N):
    if visited[i] == False:
        count += 1
        dfs(i,-1) i range(N) range N if visited[i] == False:
        count += 1
        dfs(i,-1) visited[i] == False visited[i] visited i False count += 1 count 1 dfs(i,-1) dfs i -1 print(count) print count M = map(int, input().split()) map(int, input().split()) M a, b, z = map(int, input().split()) map(int, input().split()) a z = map(int, input().split()) map(int, input().split()) z def dfs(node, prev):
    if visited[node]:
        return
    visited[node] = True
    for n in paths[node]:
        if n != prev:
            dfs(n, node) def dfs(node, prev):
    if visited[node]:
        return
    visited[node] = True
    for n in paths[node]:
        if n != prev:
            dfs(n, node) dfs b, z = map(int, input().split()) map(int, input().split()) b count += 1 1 count N, M = map(int, input().split()) map(int, input().split()) N visited = [False] * N [False] * N visited paths = [[] for _ in range(N)] [[] for _ in range(N)] paths count = 0 0 count
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())
paths = [[] for _ in range(N)]

for _ in range(M):
    a, b, z = map(int, input().split())
    paths[a-1].append(b-1)
    paths[b-1].append(a-1)

visited = [False] * N

def dfs(node, prev):
    if visited[node]:
        return
    visited[node] = True
    for n in paths[node]:
        if n != prev:
            dfs(n, node)
count = 0
for i in range(N):
    if visited[i] == False:
        count += 1
        dfs(i,-1)

print(count)
