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

groups = {}
group_count = 0
appeared = []

group_id = 0

M.times{
	x, y, z = gets.strip.split(/ /).collect(&:to_i)
	
	x_id = groups[x]
	y_id = groups[y]
	if x_id == nil && y_id == nil
		groups[x] = groups[y] = group_id
		group_id += 1
		group_count += 1
	elsif x_id == nil
		y_id << x
		groups[x] = y_id
	elsif y_id == nil
		x_id << y
		groups[y] = x_id
	elsif x_id == y_id
	else
		groups[x] = groups[y] = x_id
		group_count -= 1
	end
	appeared[x] = true
	appeared[y] = true
}

puts N - appeared.count{|flag| flag == true} + group_count
