import Control.Monad (replicateM)
import Data.List (intersect)

main :: IO()
main = do
    [_n,m] <- map read . words <$> getLine
    gate <- replicateM m $ map read . words <$> getLine
    print $ length $ solve gate

solve :: [[Int]] -> [Int]
solve [[l,r]] = [l..r]
solve ([l,r]:gs) = [l..r] `intersect` solve gs
solve _ = []