import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.Char
import Control.Monad

toTuple :: B.ByteString -> (Int, Int)
toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    table <- VUM.replicate (10^5+1) (0 :: Int)
    fts <- replicateM m $ do
        (a,b) <- toTuple <$> B.getLine
        VU.mapM_ (VUM.modify table (+1)) $ VU.fromList [a..b]
    table' <- VU.unsafeFreeze table
    print $ VU.length $ VU.filter (==m) table'