import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # graph Laplacian? N, M = map(int, readline().split()) m = map(int, read().split()) graph = [[] for _ in range(N + 1)] for a, b, c in zip(m, m, m): graph[a].append(b) graph[b].append(a) comp = [0] * (N + 1) N_comp = 0 for v in range(1, N + 1): if comp[v]: continue N_comp += 1 comp[v] = v stack = [v] while stack: v = stack.pop() for w in graph[v]: if comp[w]: continue comp[w] = comp[v] stack.append(w) print(N_comp)