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

groups = []
group_count = 0
appeared = []
not_appeared = N

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
		new_list = x_list + y_list
		new_list.each{|i|
			groups[i] = x_list + y_list
		}
		group_count -= 1
	end
	if appeared[x] == nil
		appeared[x] = true
		not_appeared -= 1
	end
	if appeared[y] == nil
		appeared[y] = true
		not_appeared -= 1
	end
}

puts not_appeared + group_count
