import Data.List
import Control.Monad

main = do
  [n, m] <- map read . words <$> getLine
  lrs <- map (map read . words) <$> replicateM m getLine :: IO [[Int]]
  print $ length $ foldl (\xs [l, r] -> filter (\x -> l <= x && x <= r) xs ) [1..n] lrs