import numpy as np

import sys

sys.setrecursionlimit(10**5+1)

input = sys.stdin.readline



def dfs(v,G,visit):

    visit[v-1]=1    

    for next in G[v-1]:        

        if visit[next-1]:

            continue

        _ = dfs(next,G,visit) 

 

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

G  = [[] for _ in range(N)]

for i in range(M):

    a,b ,_= list(map(int, input().split()))

    G[a-1].append(b)

    G[b-1].append(a)

 

count = 0



visit = np.array([0]*N)

for i in range(1,N+1):

  if visit[i-1]:

    continue

  if G[i-1]:  

    _ = dfs(i,G,visit)

  else:

    visit[i-1] = 1

  count += 1



print(count)
import sys

sys.setrecursionlimit(10**5+10)

input = sys.stdin.readline

def dfs(v,G,visit):

    visit[v-1]=1    

    for next in G[v-1]:        

        if visit[next-1]:

            continue

        _ = dfs(next,G,visit) 

 

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

G  = [[] for _ in range(N)]

for i in range(M):

    a,b ,_= list(map(int, input().split()))

    G[a-1].append(b)

    G[b-1].append(a)

    

count = 0



visit = [0]*N

for i in range(1,N+1):

  if visit[i-1]:

    continue

  if G[i-1]:  

    _ = dfs(i,G,visit)

  else:

    visit[i-1] = 1

  count += 1



print(count)
import numpy as np
import sys

sys.setrecursionlimit(10**5 + 1)
input = sys.stdin.readline


def dfs(v, G, visit):
    visit[v - 1] = 1
    for next in G[v - 1]:
        if visit[next - 1]:
            continue
        _ = dfs(next, G, visit)


N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
    a, b, _ = list(map(int, input().split()))
    G[a - 1].append(b)
    G[b - 1].append(a)
count = 0
visit = np.array([0] * N)
for i in range(1, N + 1):
    if visit[i - 1]:
        continue
    if G[i - 1]:
        _ = dfs(i, G, visit)
    else:
        visit[i - 1] = 1
    count += 1
print(count)

import sys

sys.setrecursionlimit(10**5 + 10)
input = sys.stdin.readline


def dfs(v, G, visit):
    visit[v - 1] = 1
    for next in G[v - 1]:
        if visit[next - 1]:
            continue
        _ = dfs(next, G, visit)


N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
    a, b, _ = list(map(int, input().split()))
    G[a - 1].append(b)
    G[b - 1].append(a)
count = 0
visit = [0] * N
for i in range(1, N + 1):
    if visit[i - 1]:
        continue
    if G[i - 1]:
        _ = dfs(i, G, visit)
    else:
        visit[i - 1] = 1
    count += 1
print(count)

-import numpy as np -sys.setrecursionlimit(10**5 + 1) +sys.setrecursionlimit(10**5 + 10) -visit = np.array([0] * N) +visit = [0] * N