import Control.Monad
main = do
  [n,m] <- map read . words <$> getLine
  lr <- replicateM m $ map read . words <$> getLine
  print $ max (minimum [last x | x <- lr] - maximum [head x | x <- lr] + 1) 0
