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

pairs = {}

appeared = {}

M.times{
	x, y, z = gets.strip.split(/ /).collect(&:to_i)
	
	if table = pairs[x]
		table[y] = true
	else
		pairs[x] = { y => true }
	end

	if table = pairs[y]
		table[x] = true
	else
		pairs[y] = { x => true }
	end
	
	if appeared[x] == nil
		appeared[x] = true
	end
	if appeared[y] == nil
		appeared[y] = true
	end
}

not_appeared = N - appeared.keys.length

group_count = 0
while cur = appeared.keys[0]
	appeared.delete(cur)
	queue = [cur]
	while cur = queue.pop
		pairs[cur].keys.each{|v|
			if appeared[v]
				appeared.delete(v)
				queue << v
			end
		}
	end
	
	group_count += 1
end

puts not_appeared + group_count
