def min(a, b)
  a < b ? a : b
end

N, M = gets.split(' ').map(&:to_i)

@group = {}
1.upto(N) {|i| @group[i] = i }

def root(i)
  while @group[i] != i
    i = @group[i]
  end
  i
end
def join(a, b)
  pa = root(a)
  pb = root(b)
  @group[pa] = pb
end

M.times {
  x, y, z = gets.split(' ').map(&:to_i)
  join(x, y)
}

1.upto(N) {|i| @group[i] = root(i) }

puts @group.values.uniq.size
