n,k=map(int,input().split())
dp=[0 for i in range(n)]
num=[]
dp[0]=1
mod=998244353
for i in range(k):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        num.append(j)
for i in range(n):
    num1=num
    for j in num:
        num2=num1
        if i+j<=n-1:
            dp[i+j]+=dp[i]
            dp[i+j]%=mod
        if i+j>n-1:
            num2=num1[:j+1]
        num1=num2
print(dp[n-1]%mod)