program name
    implicit none
    integer(4):: n,m
    integer(4),allocatable:: l(:), r(:)
    integer(4):: i,j

    read*, n,m
    allocate(l(m), r(m))

    do i=1,m
        read*, l(i), r(i)
    end do

    print*, max(0, minval(r) - maxval(l)+1)
end program name