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

groups = {}
group_count = 0
appeared = {}

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

puts N - appeared.keys.length + group_count
