import Control.Monad
import Data.List

solve :: [Int] -> [Int] -> Int
solve ls rs = max 0 (minimum rs - maximum ls + 1)

getInts :: IO [Int]
getInts = getLine >>= mapM readIO . words

main :: IO ()
main = do
  [n, m] <- getInts
  [ls, rs] <- transpose <$> replicateM m getInts
  print $ solve ls rs
