n, m = gets().split(' ').map(&:to_i)
xyz = []

m.times {
	x, y, z = gets().split(' ').map(&:to_i)
	xyz.push([x, y])
}

groupid = []
group = Array.new(n + 1)

grpcnt = 0
notnil = 0

xyz.each {|xj, yj|

	if group[xj] == nil && group[yj] == nil
		groupid.push(groupid.length)
		group[xj] = groupid.last
		group[yj] = groupid.last
		grpcnt += 1
		notnil += 2
	elsif group[xj] == nil
		group[xj] = group[yj]
		notnil += 1
	elsif group[yj] == nil
		group[yj] = group[xj]
		notnil += 1
	elsif groupid[group[xj]] != groupid[group[yj]]
		groupid[group[yj]] = groupid[group[xj]]
		grpcnt -= 1
	end
}

puts grpcnt + (n - notnil)
