class Node
  attr_accessor :parent
  def initialize(n)
    @parent = n
  end
end

class UnionFindTree
  attr_accessor :nodes, :parents
  def initialize(n)
    @nodes = (1..n).to_a.map{|i| Node.new(i)}
  end
  def find(x)
    #ループ版
    #while @nodes[x-1].parent != x
    #  x = @nodes[x-1].parent
    #end
    #return @nodes[x-1].parent = x

    #再帰版
    return x if x == @nodes[x-1].parent
    @nodes[x-1].parent = find(@nodes[x-1].parent)
    return @nodes[x-1].parent
  end

  def union(a,b)
    return if find(a) == find(b)
    $ans -= 1
    return @nodes[find(b)-1].parent = find(a)
  end

  def parents
    @nodes.map(&:parent)
  end
end

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

$ans = n
m.times do |i|
  x,y,z = gets.split.map(&:to_i)
  tree.union(x,y)
end

p $ans
