import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import Data.Maybe (fromJust)
import Control.Monad (forM, replicateM)

getInts :: IO [Int]
getInts = map (fst . fromJust . C.readInt) <$> C.words <$> B.getLine

main :: IO ()
main = do
    [n, m] <- getInts
    xs <- replicateM m getInts
    let [lb,ub] = foldl1 intersect xs
    print $ max 0 (ub - lb + 1)
    where
        intersect [l1,r1] [l2,r2] = [max l1 l2, min r1 r2]