import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
getIntList = map readInt . BS.words <$> BS.getLine
getIntMatrix = map (map readInt . BS.words) . BS.lines <$> BS.getContents

main = do
  [n,m] <- getIntList
  lrs <- getIntMatrix
  print $ f m lrs

f m lrs
  | max < min = 0
  | otherwise = max - min + 1
  where
    min = maximum (map head lrs)
    max = minimum (map (head . drop 1) lrs)