program C
    implicit none
    integer::N,M,i,j, max, min
    read(*,*) N, M
    do i = 1, M
        read(*,*) l, r
        if(i == 1) then
            max = r
            min = l
        else
            if(l > min) then
                min = l
            end if
            if(r < max) then
                max = r
            end if
        end if
    end do
    if(max >= min)then
        write(*,*) max - min + 1
    else
        write(*,*) 0
    end if

    stop
end program