
icase=0
if icase==0:
    n,k=map(int,input().split())
    lr=[[0]*2 for i in range(k)]
    for i in range(k):
        lr[i]=list(map(int,input().split()))
elif icase==1:
    n,k=5,2
    lr=[[1, 1], [3, 4]]
elif icase==2:
    n,k=60,3
    lr=[[5, 8], [1, 3], [10, 15]]
elif icase==3:
    n,k=30,2 
    lr=[[1,1], [6,8]]
elif icase==4:
    n,k=30,1 
    lr=[[6,8]]

mod=998244353

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

for i in range(1,n):
    for kk in range(k):
        if i+lr[kk][0]>n+1:
            continue
#for kk in range(k):
#    for i in range(1,n):
        for lri in range(lr[kk][0],min(lr[kk][1]+1,n+1)):
            j=i+lri
            if j<=n:
                dp[j]=(dp[j]+dp[i])%mod
#    print(dp)

print(dp[n])
