N, M = gets.strip.split(/ /).collect(&:to_i)

pairs = (0..N).collect{ {} }

appeared = []
not_appeared = N

M.times{
	x, y, z = gets.strip.split(/ /).collect(&:to_i)
	
	pairs[x][y] = true
	pairs[y][x] = true
	
	unless appeared[x]
		appeared[x] = true
		not_appeared -= 1
	end
	unless appeared[y]
		appeared[y] = true
		not_appeared -= 1
	end
}

def count(appeared, pairs)
	i = 1
	group_count = 0
	while true
		while appeared[i] == nil
			if i > N
				return group_count
			end
			i += 1
		end
		appeared[i] = nil
		queue = [i]
		while cur = queue.pop
			pairs[cur].keys.each{|v|
				if appeared[v]
					appeared[v] = nil
					queue << v
				end
			}
		end
		
		group_count += 1
	end
end

puts not_appeared + count(appeared, pairs)
