
import Control.Monad

solver::[(Int,Int)]->Int
solver ls = let left = map fst ls in
            let right = map snd ls in
            max 0 ((minimum right) + 1 - (maximum left))

main::IO()
main=do
  _:n:_ <- return.map read.words =<< getLine
  dat<-forM [1..n] (\_ -> return .  (\ (l:r:_) -> (l,r)) . map read . words =<< getLine )
  print (solver dat)
