-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Char
import Control.Monad
import qualified Data.ByteString.Char8 as BS

readIntPair :: BS.ByteString -> (Int, Int)
readIntPair s = let Just (a, s') = BS.readInt s
                    Just (b, _) = BS.readInt $ BS.dropWhile isSpace s'
                in (a, b)

main = do
  (n,m) <- readIntPair <$> BS.getLine
  (maxL,minR) <- fmap (foldl1' (\(!l,!r) (!l',!r') -> let !ll = max l l'; !rr = min r r' in (ll,rr))) $ replicateM m (readIntPair <$> BS.getLine)
  print $ max 0 (minR - maxL + 1)
