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=0
do i=1,n
    do j=1,m
        if (i<L(j) .or. i>R(j)) then
                exit
        end if
        if (j==m) then
            flag=flag+1
        end if
    end do
end do

write(*,*) flag


end program kadai