#!/usr/bin/ruby

require 'pp'

N,M = gets.chomp.split(" ").map(&:to_i)

table = Array.new(N+1){|i| [0,[]]}

1.upto(M){|i|
   x,y,z = gets.chomp.split(" ").map(&:to_i)
   table[x][1] << y
   table[y][1] << x
}

#pp table

count = 0
1.upto(N){|n|
   node = table[n]
   if node[0] == 0
      count+=1
      node[0] = 1
      queue = [node]
      while !queue.empty? do
         current = queue.shift
         current[1].each{|n|
            if table[n][0] == 0
               table[n][0] = 1
               queue << table[n]
            end
         }
      end
   end
}

puts count