import Control.Monad

main = do
  [n, m] <- map read . words <$> getLine
  xs <- replicateM m (map read . words <$> getLine)
  let x = concat xs
  print $ length $ func x [1..10^5]

func :: [Int] -> [Int] -> [Int]
func [] xs = xs
func (l:r:xs) ys = func xs [x | x <- ys, x >= l, x <= r]