program main
Implicit None
	integer i,N,M,count,Lmax,Rmin
	integer,allocatable :: L(:),R(:)
	read(5,*) N,M
	allocate(L(M),R(M))
	Lmax=0	;Rmin=N
	
	do i=1,M
		read(5,*) L(i),R(i)
		if(L(i).ge.Lmax)	Lmax=L(i)
		if(R(i).le.Rmin)	Rmin=R(i)
	end do
	count=Rmin-Lmax+1
	write(6,'(i0)') count

end program main