module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import qualified Data.Set as S


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine
    
solve :: [(Int, Int)] -> Int -> Int
solve lrs n = S.size $ foldl (\st (l, r) -> S.filter (\n -> n >= l && n <= r) st) initialSet lrs where
    initialSet = S.fromAscList [1..n]

main = do
    (n, m) <- readTuple2
    lrs <- replicateM m readTuple2
    print $ solve lrs n


