import sys

sys.setrecursionlimit(10**8)

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

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

for i in range(M):

  a,b,c = list(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)
N, M = list(map(int, input().split()))



class UnionFind():

  def __init__(self, n):

    self.n = n

    self.parents = [-1] * n



  def find(self, x):

    if self.parents[x] < 0:

      return x

    else:

      self.parents[x] = self.find(self.parents[x])

      return self.parents[x]



  def union(self, x, y):

    x = self.find(x)

    y = self.find(y)



    if x == y:

      return



    if self.parents[x] > self.parents[y]:

            x, y = y, x



    self.parents[x] += self.parents[y]

    self.parents[y] = x



  def roots(self):

    return [i for i, x in enumerate(self.parents) if x < 0]



uf = UnionFind(N)



for _ in range(M):

  x,y,z = list(map(int, input().split()))

  uf.union(x-1,y-1)

  

ans = len(uf.roots())

  

print(ans)

import sys

sys.setrecursionlimit(10**8)
N, M = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(M):
    a, b, c = list(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)

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


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]


uf = UnionFind(N)
for _ in range(M):
    x, y, z = list(map(int, input().split()))
    uf.union(x - 1, y - 1)
ans = len(uf.roots())
print(ans)

-import sys - -sys.setrecursionlimit(10**8) -edge = [[] for _ in range(N)] -for i in range(M): -    a, b, c = list(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 +class UnionFind: +    def __init__(self, n): +        self.n = n +        self.parents = [-1] * n + +    def find(self, x): +        if self.parents[x] < 0: +            return x +        else: +            self.parents[x] = self.find(self.parents[x]) +            return self.parents[x] + +    def union(self, x, y): +        x = self.find(x) +        y = self.find(y) +        if x == y: +            return +        if self.parents[x] > self.parents[y]: +            x, y = y, x +        self.parents[x] += self.parents[y] +        self.parents[y] = x + +    def roots(self): +        return [i for i, x in enumerate(self.parents) if x < 0] -ans = 0 -visited = [False] * N -for i in range(N): -    if visited[i] == False: -        visited[i] = True -        dfs(i) -        ans += 1 +uf = UnionFind(N) +for _ in range(M): +    x, y, z = list(map(int, input().split())) +    uf.union(x - 1, y - 1) +ans = len(uf.roots())