n,m=gets.split.map(&:to_i)
l=Array.new(n+1) {[]}
m.times do
  x,y,z=gets.split.map(&:to_i)
  l[x] << y
  l[y] << x
end
v=[0]*(n+1)
c=0
1.upto(n) do |i|
  next if v[i]==1
  c+=1
  s=[i]
  while s!=[]
    z=[]
    s.each do |j|
      l[j].each do |lj|
        if v[lj]==0
          v[lj]=1
          z << lj
        end
      end
    end
    s=z.dup
  end
end
puts c
