import Control.Monad
import Data.Graph
import qualified Data.Map as M

main = do
  [n,m]<-map read.words<$>getLine
  xys<-replicateM m $ (\[a,b]->(a,b)).map read.take 2.words<$>getLine
  let graph = buildG (1,n) xys
  print.length $ components graph

