import Control.Monad
import Data.List

solve n [] = 1
solve n ((l:r:s):lrss)
    | l <= n && n <= r = solve n lrss
    | otherwise = 0

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    lr <- replicateM m (map read . words <$> getLine) :: IO [[Int]]
    print $ sum $ map (\x -> solve x lr) [1..n]
