F =-> {gets.split.map &:to_i}
N,M = F[]
A = (0..N).map {[]}
A[0] = 1
M.times {
  a,b = F[]
  A[a] << b
  A[b] << a
}
1.upto(N) {|i|
  next  if (a=A[i]).frozen?
  A[i] = i
  while j = a.pop
    next  if (b=A[j]).frozen?
    a.concat b
    A[j] = i
  end
}
p A.tally.size-1