import sys
sys.setrecursionlimit(10 ** 7)

def dfs(s):
    if visited[s]:
        return
    visited[s] = 1
    for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
    
N, M = map(int,input().split())
t = [[] for _ in range(N)]
visited = [0] * N
for _ in range(M):
    X, Y, Z = map(int,input().split())
    X -= 1
    Y -= 1
    t[X].append(Y)
    t[Y].append(X)
ans = 0
for i in range(0, N):
    if visited[i]:
        continue
    ans += 1
    dfs(i)
print(ans) import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 def dfs(s):
    if visited[s]:
        return
    visited[s] = 1
    for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
     dfs if visited[s]:
        return
     visited[s] visited s return visited[s] = 1 visited[s] visited s 1 for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
     to t[s] t s if visited[to]:
            continue
         visited[to] visited to continue dfs(to) dfs to s s 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) [] t = [[] for _ in range(N)] t [[] for _ in range(N)] visited = [0] * N visited [0] * N [0] 0 N for _ in range(M):
    X, Y, Z = map(int,input().split())
    X -= 1
    Y -= 1
    t[X].append(Y)
    t[Y].append(X) _ range(M) range M X, Y, Z = map(int,input().split()) X map(int,input().split()) map int input().split() ().split () input split Y Z X -= 1 X 1 Y -= 1 Y 1 t[X].append(Y) [X].append [X] t X append Y t[Y].append(X) [Y].append [Y] t Y append X ans = 0 ans 0 for i in range(0, N):
    if visited[i]:
        continue
    ans += 1
    dfs(i) i range(0, N) range 0 N if visited[i]:
        continue
     visited[i] visited i continue ans += 1 ans 1 dfs(i) dfs i print(ans) print ans ans += 1 1 ans Z = map(int,input().split()) map(int,input().split()) Z t = [[] for _ in range(N)] [[] for _ in range(N)] t def dfs(s):
    if visited[s]:
        return
    visited[s] = 1
    for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
     def dfs(s):
    if visited[s]:
        return
    visited[s] = 1
    for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
     dfs Y, Z = map(int,input().split()) map(int,input().split()) Y ans = 0 0 ans visited = [0] * N [0] * N visited M = map(int,input().split()) map(int,input().split()) M X -= 1 1 X N, M = map(int,input().split()) map(int,input().split()) N Y -= 1 1 Y X, Y, Z = map(int,input().split()) map(int,input().split()) X
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(s):
    if visited[s]:
        return
    visited[s] = 1
    for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
    
N, M = map(int,input().split())
t = [[] for _ in range(N)]
visited = [0] * N
for _ in range(M):
    X, Y, Z = map(int,input().split())
    X -= 1
    Y -= 1
    t[X].append(Y)
    t[Y].append(X)
ans = 0
for i in range(0, N):
    if visited[i]:
        continue
    ans += 1
    dfs(i)
print(ans)