program kadai
implicit none

integer  ::  n,m,i,j,flag
integer,allocatable  ::  L(:)
integer,allocatable  ::  R(:)

read(*,*) n,m

allocate(L(m))
allocate(R(m))

do i=1,m
    read(*,*) L(i),R(i)
end do

flag=minval(R)-maxval(L)+1

if (flag<0) then
    flag=0
end if
write(*,*) flag


end program kadai