class UnionFind
  def initialize(n)
    @n = n
    @parent = Array.new(n){|i|i}
    @rank = Array.new(n, 0)
  end

  def find(x)
    if @parent[x] == x
      return x
    else
      return @parent[x] = find(@parent[x])
    end 
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y
    if @rank[x] < @rank[y]
      @parent[x] = y
    else
      @parent[y] = x
      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def num_of_cimponent
    h=Hash.new(0)
    @n.times{|i|
      h[find(i)]+=1
    }
    h.keys.size
  end
end

n,m=gets.split.map(&:to_i)
uf=UnionFind.new(n)
m.times{
  x,y,z=gets.split.map(&:to_i)
  uf.unite(x-1,y-1)
}

puts uf.num_of_cimponent