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

main :: IO ()
main = do
  (n, m) <- getInt2
  lrs <- getInt2s
  print $ solve n m lrs

solve :: Int -> Int -> [(Int, Int)] -> Int
solve _ _ lrs = max (r - l + 1) 0 where
  (l, r) = foldr1 f lrs
  f (l1, r1) (l2, r2) = (max l1 l2, min r1 r2)

readInt2 :: B.ByteString -> (Int, Int)
readInt2 = (\[a, b] -> (a, b)) . map (fst . fromJust . B.readInt) . B.words

getInt2 :: IO (Int, Int)
getInt2 = readInt2 <$> B.getLine

getInt2s :: IO [(Int, Int)]
getInt2s = map readInt2 . B.lines <$> B.getContents
