import sys
sys.setrecursionlimit(10**8)
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
  a,b,c = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(v):
  if len(edge[v])==0:
    return 0
  for u in edge[v]:
    if visited[u]==False:
      visited[u]=True
      dfs(u)
  return 0

ans = 0
visited = [False]*N
for i in range(N):
  if visited[i]==False:
    visited[i]=True
    dfs(i)
    ans += 1
print(ans) import sys sys sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 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) [] edge = [[] for _ in range(N)] edge [[] for _ in range(N)] for i in range(M):
  a,b,c = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1) i range(M) range M a,b,c = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c edge[a-1].append(b-1) [a-1].append [a-1] edge a-1 a 1 append b-1 b 1 edge[b-1].append(a-1) [b-1].append [b-1] edge b-1 b 1 append a-1 a 1 def dfs(v):
  if len(edge[v])==0:
    return 0
  for u in edge[v]:
    if visited[u]==False:
      visited[u]=True
      dfs(u)
  return 0 dfs if len(edge[v])==0:
    return 0
   len(edge[v])==0 len(edge[v]) len edge[v] edge v 0 return 0 0 for u in edge[v]:
    if visited[u]==False:
      visited[u]=True
      dfs(u)
   u edge[v] edge v if visited[u]==False:
      visited[u]=True
      dfs(u)
   visited[u]==False visited[u] visited u False visited[u]=True visited[u] visited u True dfs(u) dfs u return 0 0 v v ans = 0 ans 0 visited = [False]*N visited [False]*N [False] False N for i in range(N):
  if visited[i]==False:
    visited[i]=True
    dfs(i)
    ans += 1 i range(N) range N if visited[i]==False:
    visited[i]=True
    dfs(i)
    ans += 1 visited[i]==False visited[i] visited i False visited[i]=True visited[i] visited i True dfs(i) dfs i ans += 1 ans 1 print(ans) print ans edge = [[] for _ in range(N)] [[] for _ in range(N)] edge c = map(int, input().split()) map(int, input().split()) c M = map(int, input().split()) map(int, input().split()) M def dfs(v):
  if len(edge[v])==0:
    return 0
  for u in edge[v]:
    if visited[u]==False:
      visited[u]=True
      dfs(u)
  return 0 def dfs(v):
  if len(edge[v])==0:
    return 0
  for u in edge[v]:
    if visited[u]==False:
      visited[u]=True
      dfs(u)
  return 0 dfs ans = 0 0 ans visited = [False]*N [False]*N visited N, M = map(int, input().split()) map(int, input().split()) N b,c = map(int, input().split()) map(int, input().split()) b a,b,c = map(int, input().split()) map(int, input().split()) a ans += 1 1 ans
import sys
sys.setrecursionlimit(10**8)
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
  a,b,c = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(v):
  if len(edge[v])==0:
    return 0
  for u in edge[v]:
    if visited[u]==False:
      visited[u]=True
      dfs(u)
  return 0

ans = 0
visited = [False]*N
for i in range(N):
  if visited[i]==False:
    visited[i]=True
    dfs(i)
    ans += 1
print(ans)