program abc127c
  implicit none
  integer :: n, m, x
  integer,allocatable :: lr(:,:), l(:), r(:)

  read *, n, m
  allocate(lr(2,m))
  read *, lr
  l = lr(1,:)
  r = lr(2,:)
  x = minval(r)-maxval(l)+1
  print *, merge(x, 0, x > 0)
end program abc127c
