program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,i,j,l,ns
    integer(int32):: md = 998244353
    integer(int32), allocatable:: lr(:,:), s(:),dp(:)


    read*, n, k
    allocate(lr(2,k))
    do i=1,k
        read*, lr(:,i)
    end do
    allocate(s(n),source=0)
    do i=1,k
        do j=lr(1,i),lr(2,i)
            s(j) = 1
        end do
    end do

    allocate(dp(n),source=0)
    ! print'(*(i0,1x))', s(:)
    dp(1) = 1
    do i=1,n-1
        dp(i+1:n) = mod(dp(i+1:n)+mod(dp(i)*s(:n-i),md),md)
        ! print'(*(i0,1x))', dp(:)
    end do
    print'(i0)', dp(n)
end program main