n, m = gets.split.map(&:to_i)
saw = Array.new(n)
q = 0
saw_count = 0
m.times do |i|
  x, y, z = gets.split.map(&:to_i)
  q += 1 if saw[x - 1] == nil && saw[y - 1] == nil
  if saw[x - 1] == nil
    saw[x - 1] = true
    saw_count += 1
  end
  if saw[y - 1] == nil
    saw[y - 1] = true
    saw_count += 1
  end
end
puts q + (n - saw_count)
