PROGRAM ATCODER

implicit none
integer :: i,j,n,m,index=1,dp,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 = n
do i = 1, m, 1
  call chmin(dp,r(i)-l(i),index,i)
end do

do i = l(index), r(index), 1
  check = 0
  do j = 1, m, 1
    if ( i >= l(j) .and. i <= r(j) ) cycle
    check = 1
    exit
  end do
  if ( check == 0 ) then
    count = count + 1
  end if
end do

print'(i0)', count 

contains
  subroutine chmin(dp,x,index,i)
  implicit none
  integer :: dp, x, index, i

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

  end subroutine

END PROGRAM ATCODER
