from bisect import bisect_left,bisect

icase=0
if icase==0:
    n,k=map(int,input().split())

    s=[]
    for i in range(k):
        li,ri=list(map(int,input().split()))
        for i in range(li,ri+1):
            s.append(i)
elif icase==1:
    n,k=5,2
    s=[1, 3, 4]
elif icase==2:
    n,k=60,3    
    s=[5, 6, 7, 8, 1, 2, 3, 10, 11, 12, 13, 14, 15]

s.sort()

mod=998244353

dp=[0]*(n+1)
dp[1]=1

iri=[0]*(n+1)
for si in s:
    iri[si]=1
for i in range(1,n+1):
    iri[i]=iri[i]+iri[i-1]    

for i in range(1,n):
#    ir=min(bisect(s,n-i)+1,n)
    ir=min(iri[n-i]+1,n)
    for si in s[:ir]:
        j=i+si
        if j<=n:
            dp[j]=(dp[j]+dp[i])%mod
#    print(i,ir,dp)

print(dp[n])
