{-# LANGUAGE TypeApplications #-}

import           Control.Monad
import           Control.Applicative
import           Data.List
import           Data.Char
import           Control.Arrow
import           Data.Bits


main = do
  [n, m] <- map (read @Int) . words <$> getLine
  print . length . foldr1 intersect . map (\[l, r] -> [l .. r]) =<< replicateM
    m
    (map (read @Int) . words <$> getLine)
