class UnionFind():

  def __init__(self, n):

    self.n = n

    # n+1なのはノード番号とリストのインデックスを一致させるため

    # root[x]<0ならそのノードが根かつその絶対値が木の要素数

    self.root = [-1]*(n+1)

    self.rnk = [0]*(n+1)

  

  def Find_Root(self, x):

    if self.root[x] < 0:

      return x

    else:

      self.root[x] = self.Find_Root(self.root[x])

      return self.root[x]

    

  def Unite(self, x, y):

    x = self.Find_Root(x)

    y = self.Find_Root(y)

    if x == y:

      return

    elif(self.rnk[x] > self.rnk[y]):

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

      self.root[y] = x

    else:

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

      self.root[x] = y

      if self.rnk[x] == self.rnk[y]:

        self.rnk[y] += 1

 

  def isSameGroup(self, x, y):

    return self.Find_Root(x) == self.Find_Root(y)

  

  def Count(self, x):

    return -self.root[self.Find_Root(x)]



n, m = list(map(int, input().split()))

UF = UnionFind(n)

for i in range(m):

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

  UF.Unite(x,y)



print((sum(x<0 for x in UF.root[1:])))
import sys

input = sys.stdin.readline



n, m = list(map(int, input().split()))

g = [[] for _ in range(n)]

for i in range(m):

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

    x, y = x-1, y-1

    g[x].append(y)

    g[y].append(x)



s = []

visit = [-1]*n

cnt = 0

for i in range(n):

    if visit[i] == -1:

        s.append(i)

        cnt += 1

        visit[i] = cnt

        while s:

            v = s.pop()

            for u in g[v]:

                if visit[u] == -1:

                    visit[u] = visit[v]

                    s.append(u)

print((max(visit)))
class UnionFind:
    def __init__(self, n):
        self.n = n
        # n+1なのはノード番号とリストのインデックスを一致させるため
        # root[x]<0ならそのノードが根かつその絶対値が木の要素数
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

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

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]


n, m = list(map(int, input().split()))
UF = UnionFind(n)
for i in range(m):
    x, y, z = list(map(int, input().split()))
    UF.Unite(x, y)
print((sum(x < 0 for x in UF.root[1:])))

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
    x, y, z = list(map(int, input().split()))
    x, y = x - 1, y - 1
    g[x].append(y)
    g[y].append(x)
s = []
visit = [-1] * n
cnt = 0
for i in range(n):
    if visit[i] == -1:
        s.append(i)
        cnt += 1
        visit[i] = cnt
        while s:
            v = s.pop()
            for u in g[v]:
                if visit[u] == -1:
                    visit[u] = visit[v]
                    s.append(u)
print((max(visit)))

-class UnionFind: -    def __init__(self, n): -        self.n = n -        # n+1なのはノード番号とリストのインデックスを一致させるため -        # root[x]<0ならそのノードが根かつその絶対値が木の要素数 -        self.root = [-1] * (n + 1) -        self.rnk = [0] * (n + 1) +import sys -    def Find_Root(self, x): -        if self.root[x] < 0: -            return x -        else: -            self.root[x] = self.Find_Root(self.root[x]) -            return self.root[x] - -    def Unite(self, x, y): -        x = self.Find_Root(x) -        y = self.Find_Root(y) -        if x == y: -            return -        elif self.rnk[x] > self.rnk[y]: -            self.root[x] += self.root[y] -            self.root[y] = x -        else: -            self.root[y] += self.root[x] -            self.root[x] = y -            if self.rnk[x] == self.rnk[y]: -                self.rnk[y] += 1 - -    def isSameGroup(self, x, y): -        return self.Find_Root(x) == self.Find_Root(y) - -    def Count(self, x): -        return -self.root[self.Find_Root(x)] - - +input = sys.stdin.readline -UF = UnionFind(n) +g = [[] for _ in range(n)] -    UF.Unite(x, y) -print((sum(x < 0 for x in UF.root[1:]))) +    x, y = x - 1, y - 1 +    g[x].append(y) +    g[y].append(x) +s = [] +visit = [-1] * n +cnt = 0 +for i in range(n): +    if visit[i] == -1: +        s.append(i) +        cnt += 1 +        visit[i] = cnt +        while s: +            v = s.pop() +            for u in g[v]: +                if visit[u] == -1: +                    visit[u] = visit[v] +                    s.append(u) +print((max(visit)))