n,k=map(int,input().split())
s=[]
p=998244353
for i in range(k):
    l,r=map(int,input().split())
    s.append([l,r])
k=len(s)
dp=[0]*(3*n)
dp[1]=1
dp[2]=-1
for i in range(1,n):
    dp[i]=(dp[i-1]+dp[i])%p
    for j in range(k):
        l,r=s[j][0],s[j][1]
        dp[i+l]=(dp[i+l]+dp[i])%p
        dp[i+r+1]=(dp[i+r+1]-dp[i])%p

dp[n]=dp[n-1]+dp[n]

print(dp[n]%p)

