class UnionFind
  attr_accessor :parent, :rank
  
  def initialize(n)
    @parent = []
    @rank = []
    n.times do |i|
      @parent[i] = i
      @rank[i] = 0
    end
  end

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

  def unite(x,y)
    x,y = find(x),find(y)
    return if x==y

    x,y = y,x if @rank[x] < @rank[y]
    @rank[x] += 1 if @rank[x] == @rank[y]
    @parent[y] = x
  end
end

n,m = gets.split.map(&:to_i)
tree = UnionFind.new(n+1)

m.times do
  x,y,z = gets.split.map(&:to_i)
  tree.unite(x,y)
end

parents = []
1.upto(n) do |i|
  parents << tree.find(i)
end
p parents.uniq.length