import Control.Monad (replicateM)
import Data.List (intersect)

main :: IO()
main = do
    [_n,m] <- map read . words <$> getLine
    gate <- replicateM m $ map read . words <$> getLine
    print $ solve gate

solve :: [[Int]] -> Int
solve [[l,r]] = r - l + 1
solve ([l,r] : [l',r'] : gs)
  | l <= l' && r' <= r = solve ([l',r']:gs)
  | l' < l && r < r' = solve ([l,r]:gs)
  | l <= l' && r <= r' = solve ([l',r]:gs)
  | l' < l && r' < r = solve ([l,r']:gs)
  | otherwise = 0