require 'pp'
require 'set'

N,M = readline.chomp.split.map(&:to_i)

#union find
$par = Array.new(N) {|i| i}
$rank = Array.new(N,0)

def find(x)
  if $par[x] == x 
    return x
  else
    $par[x] = find($par[x])
    return $par[x]
  end
end

def unite(x,y)
  x = find(x)
  y = find(y)
  return if x == y

  if $rank[x] < $rank[y]
    $par[x] = y
  else
    $par[y] = x
    $rank[x] += 1 if $rank[x] == $rank[y]
  end
end

$edges = Array.new(N) { Array.new }
M.times do |i|
  i,j,w = readline.chomp.split.map(&:to_i)
  unite(i-1, j-1)
end

roots = Set.new
N.times do |i|
  roots << find(i)
end

puts roots.size

