n, m = gets.rstrip.split.map(&:to_i)
xyzs = m.times.map{ gets.rstrip.split.map(&:to_i) }
xys = []; xyzs.each{|xyz| xys << [xyz[0], xyz[1]]}

deleted = []
ans = 0


#
# xys から 左 or 右 に x を含む行を削除.
#   左 に x を含む場合は再帰的に 右 を含む行を削除
#   右 に x を含む場合は再帰的に 左 を含む行を削除
def rm_relevant(xys, deleted, x)
  return xys, deleted if deleted.include? x
  deleted << x

  to_del = []

  xys.reject! do | xy |
    if xy[0] == x
      to_del << xy[1] unless deleted.include? xy[1]
    end
    if xy[1] == x
      to_del << xy[0] unless deleted.include? xy[0]
    end
    xy[0] == x or xy[1] == x # x を含む行を削除
  end

  to_del.each do | x |
    xys, deleted = rm_relevant(xys, deleted, x)
  end
  return xys, deleted
end

while xys.size > 0
  xy = xys.shift
  xys, deleted = rm_relevant(xys, deleted, xy[0])
  xys, deleted = rm_relevant(xys, deleted, xy[1])
  ans += 1
end

p ans + n - deleted.size