import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= main'
    where
        main' [n, m] = readContents m >>= print . solve n m 

solve :: Int -> Int -> [[Int]] -> Int
solve n m = count . check 0 n
    where
        count (l, h) = h - l

        check x y ([l, r] : xs) = check (max x $ l - 1) (min y r) xs
        check x y _ = (x, y)


readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine