n,m = gets.strip.split.map(&:to_i)
t = 0
c = Array.new(n){[]}
m.times do
  a,b = gets.strip.split.map{|e| e.to_i - 1}
  c[a].push b
  c[b].push a
end
n.times do |i|
  if c[i] != 0
    t += 1
    c[i].each do |e|
      c[e] = 0
    end
  end
end
p t-1
