
#N=gets.to_i
#S=gets.chomp
#A=(0...N).map{gets.to_i}
#sum=A.inject(&:+)
#B=gets.split.map(&:to_i)




class WeightedUnionFind
  @par=[] # 親の番号
  @ws=[]  # 親との重みの差
  
  def initialize(n)
      @par = (0...n).to_a
      @ws  = Array.new(n,0)
  end
  
  def find(x)
      if @par[x]==x
          return x
      else
          parent = find(@par[x])
          @ws[x] += @ws[@par[x]]
          @par[x]=parent
          return parent
      end
  end
  
  def weight(x)
      find(x) 
      return @ws[x]
  end
  
  def union(x,y,w) # x <-(w)- y (x + w = y)
      w += weight(x)
      w -= weight(y)
      x = find(x)
      y = find(y)
      
      if x != y
          @par[y] = x
          @ws[y] = w
          return true
      else
          return false
      end
  end
  
  def same(x, y)
      return find(x) == find(y)
  end
  
  def diff(x,y) # x - y を求める. 比較不能ならnil
      return nil if !same(x, y)
      return weight(x) - weight(y)
  end
end


N,M=gets.split.map(&:to_i)
uf=WeightedUnionFind.new(N)

M.times do
  x,y,z=gets.split.map(&:to_i)
  uf.union(x-1,y-1,1)
end


parcount={}
N.times do |i|
  parcount[uf.find(i)]=1
end
puts parcount.size
