import Control.Monad
main=do
 [n,m]<-map read.words<$>getLine
 lr<-replicateM m (map read.words<$>getLine)
 print(f 1 n m lr)
  where f s t 0 _ =max 0 (t-s+1)
        f s t m ([l,r]:lr) = f (max s l) (min t r) (m-1) lr