N,M,*xyzs=$<.read.split.map(&:to_i)
arr = Array.new(N+1) { Array.new }
xyzs.each_slice(3).each do |x,y,z|
  arr[x] << y
  arr[y] << x
end

# p arr

i = 1
ret = 0
while i <= N
  if arr[i]
    ret += 1

    q = [arr[i]]
    arr[i] = nil
    while !q.empty?
      q.pop.each do |t|
        q << arr[t] if arr[t]
        arr[t] = nil
      end
    end
  end
  i += 1
end

p ret


