program new2
  implicit none
  integer :: N,M,i,migi,hidari
  integer,allocatable :: L(:,:)

  read(*,*) N,M

  allocate(L(M,2))
!  read(*,*) L                                                                                                                                           
  do i=1,M
     read(*,*) L(i,1),L(i,2)
  enddo
  hidari=maxval(L(:,1))
  migi=minval(L(:,2))
  !write(*,*) hidari,migi                                                                                                                                
  if(migi.lt.hidari) then
     write(*,'(i0)') 0
  else
     write(*,'(i0)') migi-hidari+1
  endif
  deallocate(L)



end program new2



