main=do
    line<-getLine
    let n=head [read x::Int|x<-words line]
    let m=last [read x::Int|x<-words line]
    ctx<-getContents
    let r=[(read (head $words x)::Int,read (last $words x)::Int)|x<- lines ctx]
    let ha=hana r
    let ta=tana r
    if ha<=ta then print (ta-ha+1) else print 0
    
hana :: [(Int,Int)]->Int
hana [x] = fst x
hana (x:xs) = max (fst x) (hana xs)

tana :: [(Int,Int)]->Int
tana [x] = snd x
tana (x:xs) = min (snd x) (tana xs)
