import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

readIntsLines :: IO [[Int]]
readIntsLines = map (map (fst . fromJust . BC.readInt) . BC.words) . BC.lines <$> BC.getContents

solve :: Int -> Int -> [[Int]] -> (Int, Int)
solve s e [] = (s, e)
solve s e ([l, r]:xs) = solve s' e' xs
  where s' = if s < l then l else s
        e' = if r < e then r else e

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  lrs <- readIntsLines
  let (l, r) = solve 1 n lrs
  print $ max 0 (r - l + 1)