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