
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad



r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


toTup [a,b] = (a,b)


main :: IO ()
main = do
    [n,m] <- r'
    (ls,rs) <- unzip . map toTup <$> replicateM m r'
    print $ max 0 (1 + minimum rs - maximum ls)
