import Control.Monad
main=do
 [n,m]<-map read.words<$>getLine :: IO [Int]
 sl<-replicateM m (map read.words<$>getLine) :: IO [[Int]]
 let sp=foldl1(\x y->let p=if head x<head y then head y else head x;q=if last x>last y then last y else last x in [p,q])sl
 print$length$[head sp..last sp]