require 'continuation'

def dfs(node, edges, known)
  stack = []
  while catch(:recur) {
          known[node] = true
          edges[node].each do |other|
            unless known[other]
              if callcc { |c| stack.push(c); true }
                node = other
                throw :recur, true
              end
            end
          end
          if stack.empty?
            false
          else
            stack.pop.call(false)
          end
        }
  end
end

n, m = gets.split.map(&:to_i)
table = m.times.map { gets.split.map(&:to_i) }
known = Array.new(n)
edges = Hash.new { [] }

table.each do |x, y, z|
  x -= 1
  y -= 1
  edges[x] <<= y
  edges[y] <<= x
end

cost = 0
(0...n).each do |i|
  unless known[i]
    cost +=1

    dfs(i, edges, known)
  end
end
puts cost
