import Control.Monad
import Data.List

solve l' r' [] = [l',r']
solve l' r' ((l:r:s):lrss) = solve l'' r'' lrss
    where
        l'' = if l' <= l then l else l'
        r'' = if r' >= r then r else r'

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    lr <- replicateM m (map read . words <$> getLine) :: IO [[Int]]
    let [l,r] = solve 1 n lr
    print $ if (r-l) >= 0 then r-l+1 else 0

