n,k=map(int,input().split())
s=[]
for i in range(k):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        s.append(j)

dp=[0]*n
dp[0]=1

smax=max(s)

for i in range(0,n):
    for j in range(max(0,i-smax),i):
        if i-j in s:
            dp[i]+=dp[j]

print(dp[n-1]%998244353)
