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

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(S)
        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[2]+=1
    for i in 2:length(Smax)-1
        if nk[i]>Smax[i]
            nk[i]=0
            nk[i+1]+=1
        end
    end
    if nk[length(Smax)]>Smax[end]
        return false
    end
    true
end       

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

flag=true

while flag
    NOKORI=nokori(nk)
    if NOKORI % S[1] == 0 && NOKORI ≥ 0
        nk[1]=NOKORI÷S[1]
        chk+=calcP(nk)
        chk%=MOD
    end
    flag=S_plus(nk)
end
print(chk)
        
end
ABC_D()
