printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

# # # # unionfind.py # # # #

# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b)

class Unionfind:

  def __init__(s,n):
    s.sz = [1] * n
    s.ances = [i for i in range(n)]

  def root(s,x):
    a = []
    y = x
    while s.ances[y] != y:
      a.append(y)
      y = s.ances[y]
    for z in a:
      s.ances[z] = y
    return y

  def conn(s,x,y):
    i = s.root(x)
    j = s.root(y)
    if i==j:
      return
    #k  = [i,j].min
    k  = j if (s.sz[i]<s.sz[j]) else i
    if k==j:
      s.ances[i] = j
    else:
      s.ances[j] = i
    s.sz[k] = s.sz[i] + s.sz[j]

# # # # end unionfind.py # # # #

n,m = inm()
uf = Unionfind(n+1)
for i in range(m):
    x,y,z = inm()
    uf.conn(x,y)
a = [0]*(n+1)
for i in range(1,n+1):
    a[uf.root(i)] = 1
print(sum(a)) printn = lambda x: print(x,end='') printn lambda x: print(x,end='') print(x,end='') print x end='' end '' x inn = lambda : int(input()) inn lambda : int(input()) int(input()) int input() input inl   = lambda: list(map(int, input().split())) inl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split inm   = lambda:      map(int, input().split()) inm lambda:      map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split ins = lambda : input().strip() ins lambda : input().strip() input().strip() ().strip () input strip DBG = True DBG True BIG = 10**18 BIG 10**18 10 18 R = 10**9 + 7 R 10**9 + 7 10**9 10 9 7 def ddprint(x):
  if DBG:
    print(x)

# # # # unionfind.py # # # #

# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b) ddprint if DBG:
    print(x)

# # # # unionfind.py # # # #

# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b) DBG print(x) print x x x class Unionfind:

  def __init__(s,n):
    s.sz = [1] * n
    s.ances = [i for i in range(n)]

  def root(s,x):
    a = []
    y = x
    while s.ances[y] != y:
      a.append(y)
      y = s.ances[y]
    for z in a:
      s.ances[z] = y
    return y

  def conn(s,x,y):
    i = s.root(x)
    j = s.root(y)
    if i==j:
      return
    #k  = [i,j].min
    k  = j if (s.sz[i]<s.sz[j]) else i
    if k==j:
      s.ances[i] = j
    else:
      s.ances[j] = i
    s.sz[k] = s.sz[i] + s.sz[j]

# # # # end unionfind.py # # # # Unionfind def __init__(s,n):
    s.sz = [1] * n
    s.ances = [i for i in range(n)]

   __init__ s.sz = [1] * n s.sz s sz [1] * n [1] 1 n i for i in range(n) for i in range(n) i range(n) range n for i in range(n) i s.ances = [i for i in range(n)] s.ances s ances [i for i in range(n)] s s n n def root(s,x):
    a = []
    y = x
    while s.ances[y] != y:
      a.append(y)
      y = s.ances[y]
    for z in a:
      s.ances[z] = y
    return y

   root a = [] a [] y = x y x while s.ances[y] != y:
      a.append(y)
      y = s.ances[y]
     s.ances[y] != y s.ances[y] s.ances s ances y y a.append(y) a.append a append y y = s.ances[y] y s.ances[y] s.ances s ances y for z in a:
      s.ances[z] = y
     z a s.ances[z] = y s.ances[z] s.ances s ances z y return y y s s x x def conn(s,x,y):
    i = s.root(x)
    j = s.root(y)
    if i==j:
      return
    #k  = [i,j].min
    k  = j if (s.sz[i]<s.sz[j]) else i
    if k==j:
      s.ances[i] = j
    else:
      s.ances[j] = i
    s.sz[k] = s.sz[i] + s.sz[j]

# # # # end unionfind.py # # # # conn i = s.root(x) i s.root(x) s.root s root x j = s.root(y) j s.root(y) s.root s root y if i==j:
      return
    #k  = [i,j].min
     i==j i j return k  = j if (s.sz[i]<s.sz[j]) else i k j if (s.sz[i]<s.sz[j]) else i s.sz[i]<s.sz[j] s.sz[i] s.sz s sz i s.sz[j] s.sz s sz j j i if k==j:
      s.ances[i] = j
    else:
      s.ances[j] = i
     k==j k j s.ances[i] = j s.ances[i] s.ances s ances i j s.ances[j] = i s.ances[j] s.ances s ances j i s.sz[k] = s.sz[i] + s.sz[j] s.sz[k] s.sz s sz k s.sz[i] + s.sz[j] s.sz[i] s.sz s sz i s.sz[j] s.sz s sz j s s x x y y n,m = inm() n inm() inm m uf = Unionfind(n+1) uf Unionfind(n+1) Unionfind n+1 n 1 for i in range(m):
    x,y,z = inm()
    uf.conn(x,y) i range(m) range m x,y,z = inm() x inm() inm y z uf.conn(x,y) uf.conn uf conn x y a = [0]*(n+1) a [0]*(n+1) [0] 0 n+1 n 1 for i in range(1,n+1):
    a[uf.root(i)] = 1 i range(1,n+1) range 1 n+1 n 1 a[uf.root(i)] = 1 a[uf.root(i)] a uf.root(i) uf.root uf root i 1 print(sum(a)) print sum(a) sum a x,y,z = inm() inm() x n,m = inm() inm() n y,z = inm() inm() y a = [0]*(n+1) [0]*(n+1) a z = inm() inm() z R = 10**9 + 7 10**9 + 7 R BIG = 10**18 10**18 BIG uf = Unionfind(n+1) Unionfind(n+1) uf inn = lambda : int(input()) lambda : int(input()) inn inm   = lambda:      map(int, input().split()) lambda:      map(int, input().split()) inm def ddprint(x):
  if DBG:
    print(x)

# # # # unionfind.py # # # #

# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b) def ddprint(x):
  if DBG:
    print(x)

# # # # unionfind.py # # # #

# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b) ddprint DBG = True True DBG printn = lambda x: print(x,end='') lambda x: print(x,end='') printn ins = lambda : input().strip() lambda : input().strip() ins m = inm() inm() m inl   = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) inl class Unionfind:

  def __init__(s,n):
    s.sz = [1] * n
    s.ances = [i for i in range(n)]

  def root(s,x):
    a = []
    y = x
    while s.ances[y] != y:
      a.append(y)
      y = s.ances[y]
    for z in a:
      s.ances[z] = y
    return y

  def conn(s,x,y):
    i = s.root(x)
    j = s.root(y)
    if i==j:
      return
    #k  = [i,j].min
    k  = j if (s.sz[i]<s.sz[j]) else i
    if k==j:
      s.ances[i] = j
    else:
      s.ances[j] = i
    s.sz[k] = s.sz[i] + s.sz[j]

# # # # end unionfind.py # # # # class Unionfind:

  def __init__(s,n):
    s.sz = [1] * n
    s.ances = [i for i in range(n)]

  def root(s,x):
    a = []
    y = x
    while s.ances[y] != y:
      a.append(y)
      y = s.ances[y]
    for z in a:
      s.ances[z] = y
    return y

  def conn(s,x,y):
    i = s.root(x)
    j = s.root(y)
    if i==j:
      return
    #k  = [i,j].min
    k  = j if (s.sz[i]<s.sz[j]) else i
    if k==j:
      s.ances[i] = j
    else:
      s.ances[j] = i
    s.sz[k] = s.sz[i] + s.sz[j]

# # # # end unionfind.py # # # # Unionfind
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

# # # # unionfind.py # # # #

# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b)

class Unionfind:

  def __init__(s,n):
    s.sz = [1] * n
    s.ances = [i for i in range(n)]

  def root(s,x):
    a = []
    y = x
    while s.ances[y] != y:
      a.append(y)
      y = s.ances[y]
    for z in a:
      s.ances[z] = y
    return y

  def conn(s,x,y):
    i = s.root(x)
    j = s.root(y)
    if i==j:
      return
    #k  = [i,j].min
    k  = j if (s.sz[i]<s.sz[j]) else i
    if k==j:
      s.ances[i] = j
    else:
      s.ances[j] = i
    s.sz[k] = s.sz[i] + s.sz[j]

# # # # end unionfind.py # # # #

n,m = inm()
uf = Unionfind(n+1)
for i in range(m):
    x,y,z = inm()
    uf.conn(x,y)
a = [0]*(n+1)
for i in range(1,n+1):
    a[uf.root(i)] = 1
print(sum(a))
