require "pp"

class UnionFind
  attr_reader :par

  def initialize list
    @par = {}
    list.each{|x| @par[x] = x}
  end

  def root x
    return x if par[x] == x
    return par[x] = root(par[x])
  end

  def unite(x, y)
    rx = root x
    ry = root y
    return if rx == ry
    par[rx] = ry
  end
end

class Main
  def run()
    # Read
    n, m = gets.split(" ").map(&:to_i)
    x_y_z_list = []
    m.times do |i|
      x_y_z_list << gets.split(" ").map(&:to_i)
    end

    # Build Union Find
    union_find = UnionFind.new((1..n).to_a)
    x_y_z_list.each do |x_y_z|
      x, y, z = x_y_z
      union_find.unite(x, y)
    end

    puts union_find.par.map{|i, x| i == x}.delete_if{|x| !x}.count
  end
end

main = Main.new()
main.run()
