import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import Data.Char

toTuple :: B.ByteString -> (Int, Int)
toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

step :: MP.Map Int Int -> (Int, Int) -> MP.Map Int Int
step m (f,t) = foldl step' m [f..t]
    where
        step' :: MP.Map Int Int -> Int -> MP.Map Int Int
        step' n x = MP.insertWith (+) x 1 n

count mp gs acc x =
        case MP.lookup x mp of
            Just res ->
                case compare res gs of
                    EQ -> acc + 1
                    _ -> acc
            Nothing -> acc

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    fts <- VU.replicateM m (toTuple <$> B.getLine)
    let mp = VU.foldl' step MP.empty fts
    print $ foldl (count mp m) 0 [1..n]