n, m = gets.split.map(&:to_i)
group = []

m.times do |i|
  x, y = gets.split(&:to_i)
  flg = nil

  group.each(&:uniq!) if i % 30 == 0
  group.each do |g|
    if g.include? 
      g.push y
      flg = 1
    elsif g.include? y
      g.push x
      flg = 1
    end
  end

  group.push [x, y] unless flg
end

puts group.size + n - group.flatten.uniq.size