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]

mod=998244353

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

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

print(dp[n])
