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