N, M = gets.split.map(&:to_i)
XYZs = readlines.map{|l| l.split.map(&:to_i)}

@p = Array.new(N + 1, -1)

def root(x)
  @p[x] < 0 ? x : @p[x] = root(@p[x])
end

def unite(x, y)
  x, y = root(x), root(y)
  if x != y
    x, y = y, x if @p[y] < @p[x]
    @p[x] += @p[y]
    @p[y] = x
  end
end

XYZs.each{|x, y, z| unite(x, y)}
puts (1 .. N).map{|i| root(i)}.uniq.size