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 $ length $ foldl1' intersect $ map (\[x, y] -> [x..y]) l
