import Data.Maybe
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b

a~>(f,x) = [a] ++ (null x)?([],f x)

main = do
 [n,k] <- readLnInt
 inputs <- readCsInt (2*k)
 print $ solve n k inputs

solve n k s = n - (length treatable) where
  treatable = nub $ trim s

trim [] = []
trim (a:as) = (take a as) ++ trim (drop a as)
