program main
implicit none
integer :: n, m
integer , allocatable :: l(:), r(:)
integer :: i

read(*,*) n, m
allocate(l(m))
allocate(r(m))
do i = 1, m
read(*,*) l(i), r(i)
end do
write(*,'(i0)') -maxval(l)+minval(r)+1

end program main
