PROGRAM ATCODER

implicit none
integer :: i,j,n,m,index=1,dp,dp2,check,count=0
integer,allocatable :: l(:),r(:)

read*, n,m 
allocate(l(m),r(m))
do i = 1, m, 1
  read*, l(i),r(i)
end do

dp = 1
dp2 = n
do i = 1, m, 1
  call chmax(dp,l(i))
  call chmin(dp2,r(i))
end do

if ( dp2 - dp < 0 ) then
  print'(i0)', 0
else
  print'(i0)', dp2 - dp + 1
end if

contains
  subroutine chmax(dp,x)
  implicit none
  integer :: dp, x

  if (dp < x) then
  	dp = x
  	return
  end if

  end subroutine

  subroutine chmin(dp,x)
  implicit none
  integer :: dp, x

  if (dp > x) then
  	dp = x
  	return
  end if

  end subroutine

END PROGRAM ATCODER