import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import Debug.Trace

main :: IO ()
main = do
    [n,m]  <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    ns <- replicateM m ((\[a,b]->(a,b)) .
            map (fst . fromJust . B.readInt) . B.words <$> B.getLine)
    print . length . merge . sort $ ns

merge ((a,b):(c,d):ns)
    | a <= c && b <= d && c < b = merge ((c, b):ns)
    | a <= c && d <= b && c < d = merge ((c, d):ns)
    | c <= a && b <= d && a < b = merge ((a, b):ns)
    | c <= a && d <= b && a < d = merge ((a, d):ns)
    | otherwise                  = (a,b) : merge ((c,d):ns)
merge ns = ns
