program leaping_tak
  implicit none
  integer(8), parameter :: modu = 998244353
  integer :: n, k, l(10) = 0, r(10) = 0, i, j, p, q
  integer(8) :: dp(200000) = 0, s(0:200000) = 0
  read(*,*) n, k
  do i = 1, k
    read(*,*) l(i), r(i)
  end do
  dp(1) = 1
  s(1) = 1
  do i = 2, n
    do j = 1, k
      p = max(i - l(j), 0)
      q = max(i - r(j) - 1, 0)
      dp(i) = modulo(dp(i) + s(p) - s(q), modu)
    end do
    s(i) = s(i - 1) + dp(i)
  end do
  write(*,'(i0)') dp(n)
end program leaping_tak