function ABC_D()
    readints()=parse.(Int,split(readline()))
    MOD=998244353
    N,K=readints()

    L=zeros(Int,K)
    R=zeros(Int,K)
    for i in 1:K
        L[i],R[i]=readints()
    end
    S0=Set(hcat(L,R))
    S=sort!(collect(S0))


    NMax = 2*10^5
    fac=ones(Int,NMax)#factorial_mod
    for i in 2:NMax
        fac[i]=fac[i-1]*i%MOD
    end

    function CMOD(a,b)#binominal_mod
        fac[a]*invmod(fac[b],MOD)%MOD*invmod(fac[a-b],MOD)%MOD
    end
    N1=N-1

    nk=zeros(Int,length(S))
    function nokori(nk)
        N1-(sum(S .* nk)-S[1]*nk[1])
    end
    function calcP(nk)

        ret=fac[sum(nk)]
        for i in 1:length(nk)
            if nk[i]==0
                im =  1
            else
                im= invmod(fac[nk[i]],MOD)
            end
            ret*=im
            ret%=MOD
        end
        ret
    end

    function S_plus(nk)
        nk[end]+=1
        for i in length(nk):-1:3
            if nk[i]>Smax[i]
                nk[i]=0
                nk[i-1]+=1
            end
        end
        if length(nk)>1
            if nk[2]>Smax[end]
                return false
            end
        else
            return false
        end
        true
    end       

    nk=zeros(Int,length(S))
    Smax=@. N1 ÷ S
    chk=0

    flag=true
    println(S)
    while flag
        NOKORI=nokori(nk)
        if NOKORI % S[1] == 0 && NOKORI ≥ 0
            nk[1]=NOKORI÷S[1]
            println("$nk = > $(sum(nk.*S))")
            chk+=calcP(nk)
            chk%=MOD
        end
        flag=S_plus(nk)
    end
    print(chk)
end
    
ABC_D()