
import Control.Monad

func :: [(Int,Int)] -> (Int,Int)-> (Int,Int)
func [] result  = result
func ((l,r):rest) (_l,_r) =
    func rest (max l _l, min r _r)


main :: IO ()
main = do
    [n , m] <- map (read) . words <$> getLine :: IO [Int]
    lines <- replicateM m getLine 
    let array = do
        line <- lines
        let [l, r] = map read $ words line :: [Int]
        return (l, r)

    let (l,r) = func array (minBound,maxBound)
    
    print $ max 0 (r - l + 1)




