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

input = []
m.times do |i|
  input[i] = gets.split(&:to_i)
end
input.shuffle!

group = []
m.times do |i|
  x, y = input[i]
  flg = nil

  group.each do |g|
    if (g.include? x) && !(g.include? y)
      g.push y
      flg = 1
    elsif (g.include? y) && !(g.include? x)
      g.push x
      flg = 1
    elsif (g.include? x) && (g.include? y)
      flg = 1
    end
  end

  group.push [x, y] unless flg
end

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