import sys;sys.setrecursionlimit(10**9)

class u():#UnionFind f-根探し u-連結 s-連結? c-要素数

  def __init__(self,n):self.n,self.r=[-1]*n,[0]*n

  def f(self,x):

    if self.n[x]<0:return x

    else:self.n[x]=self.f(self.n[x]);return self.n[x]

  def u(self,x,y):

    x,y=self.f(x),self.f(y)

    if x==y:return

    elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x

    else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y]

  def s(self,x,y):return self.f(x)==self.f(y)

  def c(self,x):return -self.n[self.f(x)]

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

for i in range(m):

  a,b,c=list(map(int,input().split()));a-=1;b-=1

  if not(u.s(a,b)):n-=1;u.u(a,b)

print(n)
import sys;sys.setrecursionlimit(10**9)

class UnionFind:

  def __init__(self,n):

    self.n=[-1]*n

    self.r=[0]*n

    self.siz=n

  def find_root(self,x):

    if self.n[x]<0:

      return x

    else:

      self.n[x]=self.find_root(self.n[x])

      return self.n[x]

  def unite(self,x,y):

    x=self.find_root(x)

    y=self.find_root(y)

    if x==y:return

    elif self.r[x]>self.r[y]:

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

      self.n[y]=x

    else:

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

      self.n[x]=y

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

        self.r[y]+=1

    self.siz-=1

  def root_same(self,x,y):

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

  def count(self,x):

    return -self.n[self.find_root(x)]

  def size(self):

    return self.siz



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-1,y-1)

print((uf.size()))
import sys

sys.setrecursionlimit(10**9)


class u:  # UnionFind f-根探し u-連結 s-連結? c-要素数
    def __init__(self, n):
        self.n, self.r = [-1] * n, [0] * n

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

    def u(self, x, y):
        x, y = self.f(x), self.f(y)
        if x == y:
            return
        elif self.r[x] > self.r[y]:
            self.n[x] += self.n[y]
            self.n[y] = x
        else:
            self.n[y] += self.n[x]
            self.n[x] = y
            self.r[y] += self.r[x] == self.r[y]

    def s(self, x, y):
        return self.f(x) == self.f(y)

    def c(self, x):
        return -self.n[self.f(x)]


n, m = list(map(int, input().split()))
u = u(n)
for i in range(m):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    if not (u.s(a, b)):
        n -= 1
        u.u(a, b)
print(n)

import sys

sys.setrecursionlimit(10**9)


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

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

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.r[x] > self.r[y]:
            self.n[x] += self.n[y]
            self.n[y] = x
        else:
            self.n[y] += self.n[x]
            self.n[x] = y
            if self.r[x] == self.r[y]:
                self.r[y] += 1
        self.siz -= 1

    def root_same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.n[self.find_root(x)]

    def size(self):
        return self.siz


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 - 1, y - 1)
print((uf.size()))

-class u:  # UnionFind f-根探し u-連結 s-連結? c-要素数 +class UnionFind: -        self.n, self.r = [-1] * n, [0] * n +        self.n = [-1] * n +        self.r = [0] * n +        self.siz = n -    def f(self, x): +    def find_root(self, x): -            self.n[x] = self.f(self.n[x]) +            self.n[x] = self.find_root(self.n[x]) -    def u(self, x, y): -        x, y = self.f(x), self.f(y) +    def unite(self, x, y): +        x = self.find_root(x) +        y = self.find_root(y) -            self.r[y] += self.r[x] == self.r[y] +            if self.r[x] == self.r[y]: +                self.r[y] += 1 +        self.siz -= 1 -    def s(self, x, y): -        return self.f(x) == self.f(y) +    def root_same(self, x, y): +        return self.find_root(x) == self.find_root(y) -    def c(self, x): -        return -self.n[self.f(x)] +    def count(self, x): +        return -self.n[self.find_root(x)] + +    def size(self): +        return self.siz -u = u(n) +uf = UnionFind(n) -    a, b, c = list(map(int, input().split())) -    a -= 1 -    b -= 1 -    if not (u.s(a, b)): -        n -= 1 -        u.u(a, b) -print(n) +    x, y, z = list(map(int, input().split())) +    uf.unite(x - 1, y - 1) +print((uf.size()))