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
    ns = sum(lr(2,:)-lr(1,:))+k
    allocate(s(ns))
    j=1
    do i=1,k
        s(j:j+(lr(2,i)-lr(1,i))) = [(l,l=lr(1,i),lr(2,i))]
        j=j+lr(2,i)-lr(1,i)+1
    end do

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