n,m = gets.chomp.split.map(&:to_i)

class UnionFind
	def initialize n
		@parent = Array.new(n,&:itself)
		@rank = Array.new(n,0)
	end

	def get_parent n
		if @parent[n] == n
			n
		else
			@parent[n] = get_parent(n)
		end
	end

	def unite x,y
		x = get_parent(x)
		y = get_parent(y)
		x,y = y,x if @rank[x] < @rank[y]
		@parent[y] = x
		@rank[y] += 1 if @rank[x] == @rank[y]
	end

	def size
		@parent.uniq.size
	end
end

union = UnionFind.new(n)
m.times do
	x,y,z = gets.chomp.split.map(&:to_i)
	union.unite(x-1,y-1)
end

puts union.size