N,M = gets.chomp.split(" ").map(&:to_i)
x,y,z = M.times.map{gets.split.map(&:to_i)}.transpose
arr = Array.new(N+1){Array.new}
cnt = N
M.times do |i|
  if arr[x[i]].length == 0 || arr[y[i]].length == 0
    cnt -= 1
  end
  arr[x[i]].push(y[i])
  arr[y[i]].push(x[i])
end
puts cnt