import Control.Monad
main = do
  [n,m] <- map read . words <$> getLine
  lr <- replicateM m $ do
    [a,b] <- map read . words <$> getLine
    return (a,b)
  let (l,r) = unzip lr
  print $ max 0 (minimum r - maximum l + 1)