import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.Vector.Unboxed.Mutable as V
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

solve :: [(Int,Int)] -> Int -> Int -> Int
solve [] l r = r - l + 1
solve ((l,r):ls) maxl minr = solve ls (max maxl l) (min minr r)

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine :: IO [Int]
  list <- replicateM m $ do
    [l,r] <- map read.words <$> getLine :: IO [Int]
    return (l,r)
  print $ solve list 0 100000
