import Control.Monad (replicateM)

main :: IO ()
main = do
  [n,m] <- map (read :: String -> Int) . words <$> getLine
  lrs <- map (map (read :: String -> Int) . words) <$> getNLine_ m
  print $ ans lrs

ans :: [[Int]] -> Int
ans lrs = (\[a,b] -> if a > b then 0 else b-a+1) $ foldl1 func lrs where
  func [l1,r1] [l2,r2] = [max l1 l2, min r1 r2]

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine