import Control.Monad
import Data.List
main = do
    [n, m] <- map read . words <$> getLine
    l <- map (map (read :: String -> Int) . words) <$> replicateM m getLine
    print $ (\[x, y] -> sub2 x y) $ foldl1' sub l
    where sub [a, b] [c, d] = [max a c, min b d]
          sub2 a b | b - a < 0 = 0
                   | otherwise = b - a + 1
