program main
Implicit None
	integer(8)::n,m,i,k
	integer(8),allocatable::l(:),r(:),g(:)
	
	read*,n,m
	allocate(l(m),r(m),g(n+1))
	
	g = 0
	do i = 1,m
		read*,l(i),r(i)
		g(l(i)) = g(l(i))+1
		g(r(i)+1) = g(r(i)+1)-1
	enddo
	
	do i = 2,n
		g(i) = g(i-1)+g(i)
	enddo
	
	k = 0
	do i = 1,n
		if(g(i) == m) k = k+1
	enddo
	
	print"(i0)",k
end program main