class Node
  attr_accessor :self, :parent
  def initialize(i)
    @self, @parent = i, i
  end
end

class UnionFindTree
  attr_accessor :nodes

  #
  def initialize(n)
    @nodes = (1..n).map{|i| Node.new(i) }
  end

  # 1番上の親を返す.
  def root(x)
    return x if x == @nodes[x-1].parent
    return @nodes[x-1].parent = root(@nodes[x-1].parent)
  end

  # 判定する
  #   2つの木が同じ親に属していればtrue
  def check(a, b)
    return true if root(a) == root(b)
    return false
  end

  # まとめる
  def union(a, b)
    return if check(a, b)
    #$ans -= 1
    @nodes[root(b)-1].parent = root(a)
  end

  #
  def parent_size
    size = 0
    @nodes.each do | node |
      size += 1 if node.self == node.parent
    end
    return size
  end
end

n, m = gets.rstrip.split.map(&:to_i)
tree = UnionFindTree.new(n)
#p tree

#$ans = n
m.times do
  x, y, _ = gets.rstrip.split.map(&:to_i)
  tree.union(x, y)
end
#p $ans
p tree.parent_size