import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

toTuple :: B.ByteString -> (Int, Int)
toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    fts <- VU.replicateM m (toTuple <$> B.getLine)
    let (l,r) = VU.foldl' (\(f,t) (f',t') -> (max f f', min t t')) (1,n) fts
    print $ max 0 (r-l+1)